state

package
v3.0.0-pre-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const Version = 0.1

Variables

View Source
var ErrNoChunkFile = errors.New("no linked chunk file")

Functions

This section is empty.

Types

type ErrStateVersion

type ErrStateVersion struct {
	Expected float64
	Actual   float64
}

ErrStateVersion is returned when the state version does not match the expected version.

func (ErrStateVersion) Error

func (e ErrStateVersion) Error() string

type State

type State struct {
	// Version is the version of the state file.
	Version float64 `json:"version"`
	// ChunkFilename is the original chunks filename for which the state is valid.
	// It may be empty.
	ChunkFilename string `json:"chunk_filename,omitempty"`
	// IsComplete indicates that all chunks were written to the file.
	IsComplete bool `json:"is_complete"`
	// Directory with downloaded files, if any.
	FilesDir string `json:"files_dir,omitempty"`
	// IsCompressed indicates that the chunk file is compressed.
	IsCompressed bool `json:"is_compressed,omitempty"`
	// Channels is a map of channel ID to the latest message timestamp.
	Channels map[_id]int64 `json:"channels,omitempty"`
	// Threads is a map of channel ID + thread timestamp to the latest message
	// timestamp in that thread.
	Threads map[_idAndThread]int64 `json:"threads,omitempty"`
	// Files is a map of file ID to the channel ID where it was posted.
	Files map[_id]_id `json:"files,omitempty"`
	// ChannelInfos contains the list of all channels in the state file.
	ChannelInfos []string `json:"channel_infos,omitempty"`
	// contains filtered or unexported fields
}

State is a struct that holds the state of the Slack dump.

func Load

func Load(filename string) (*State, error)

Load loads the state from the given file.

func New

func New(filename string) *State

New returns a new State.

func (*State) AddChannel

func (s *State) AddChannel(info string)

AddChannel should be called when a channel is processed.

func (*State) AddFile

func (s *State) AddFile(channelID, fileID string, path string)

AddFile adds a file to index. It should be called when a file is processed.

func (*State) AddMessage

func (s *State) AddMessage(channelID, messageTS string)

AddMessage indexes the message. It should be called when a message is processed.

func (*State) AddThread

func (s *State) AddThread(channelID, threadTS, ts string)

AddThread adds a thread to index. It should be called when a thread is processed.

func (*State) AllFiles

func (s *State) AllFiles(channelID string) []string

AllFiles returns all saved files for the given channel.

func (*State) FileChannelID

func (s *State) FileChannelID(id string) string

FileChannelID returns the channel ID where the file was last seen.

func (*State) FilePath

func (s *State) FilePath(channelID, fileID string) string

FilePath returns the file path for the given file ID in the given channel.

func (*State) HasChannel

func (s *State) HasChannel(id string) bool

HasChannel returns true if the channel is known (has at least one message).

func (*State) HasFile

func (s *State) HasFile(id string) bool

HasFile returns true if the file is known.

func (*State) HasThread

func (s *State) HasThread(channelID, threadTS string) bool

HasThread returns true if the thread is known (has at least one message).

func (*State) LatestChannelTS

func (s *State) LatestChannelTS(id string) string

LatestChannelTS returns the latest known message timestamp for the given channel.

func (*State) LatestThreadTS

func (s *State) LatestThreadTS(channelID, threadTS string) string

LatestThreadTS returns the latest known message timestamp for the given thread.

func (*State) OpenChunks

func (st *State) OpenChunks(basePath string) (io.ReadSeekCloser, error)

OpenChunks attempts to open the chunk file linked in the State. If the chunk is compressed, it will be decompressed and a temporary file will be created. The temporary file will be removed when the OpenChunks is closed.

func (*State) Save

func (s *State) Save(filename string) error

Save saves the state to the given file.

func (*State) SaveFSA

func (s *State) SaveFSA(fsa fsadapter.FS, filename string) error

SaveFSA saves the state to the given file in the filesystem adapter.

func (*State) SetChunkFilename

func (s *State) SetChunkFilename(filename string) *State

func (*State) SetFilesDir

func (s *State) SetFilesDir(dir string) *State

func (*State) SetIsComplete

func (s *State) SetIsComplete(isComplete bool) *State

func (*State) SetIsCompressed

func (s *State) SetIsCompressed(isCompressed bool) *State

type Stater

type Stater interface {
	// State should return the State of the underlying type.
	State() (*State, error)
}

Stater is an interface for types that can return a State.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL