Documentation ¶
Overview ¶
Package tgstore implements an encrypted object storage system with unlimited space backed by Telegram.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Object ¶
type Object struct { ID string Size int64 Checksum []byte // contains filtered or unexported fields }
Object is the unit of the `TGStore`.
type ObjectReader ¶
type ObjectReader struct {
// contains filtered or unexported fields
}
ObjectReader is the reader of the `Object`.
func (*ObjectReader) Close ¶
func (or *ObjectReader) Close() error
Close implements the `io.Closer`.
func (*ObjectReader) Read ¶
func (or *ObjectReader) Read(b []byte) (int, error)
Read implements the `io.Reader`.
type TGStore ¶
type TGStore struct { // BotAPIEndpoint is the endpoint of the Telegram Bot API. // // You might prefer to use your local Telegram Bot API server. See // https://core.telegram.org/bots/api#using-a-local-bot-api-server for // benefits. // // Default value: "https://api.telegram.org" BotAPIEndpoint string `mapstructure:"bot_api_endpoint"` // BotToken is the Telegram bot token. // // Default value: "" BotToken string `mapstructure:"bot_token"` // ChatID is the ID of the Telegram chat used to store the objects to be // uploaded. // // It is ok to change the `ChatID` if you want. The objects that have // already been uploaded are not affected. // // Default value: 0 ChatID int64 `mapstructure:"chat_id"` // MaxFileBytes is the maximum number of bytes allowed for a Telegram // file to have. // // The `MaxFileBytes` must be at least 20971520 (20 MiB). // // It is ok to change the `MaxFileBytes` if you want. The objects that // have already been uploaded are not affected. // // Default value: 20971520 MaxFileBytes int `mapstructure:"max_file_bytes"` // MaxObjectMetadataCacheBytes is the maximum number of bytes allowed // for object metadata cache to use. // // The `MaxObjectMetadataCacheBytes` must be at least 1048576 (1 MiB). // // Default value: 1048576 MaxObjectMetadataCacheBytes int `mapstructure:"max_object_metadata_cache_bytes"` // HTTPClient is the `http.Client` used to communicate with the Telegram // Bot API. // // Default value: `http.DefaultClient` HTTPClient *http.Client `mapstructure:"-"` // contains filtered or unexported fields }
TGStore is the top-level struct of this project.
It is highly recommended not to modify the value of any field of the `TGStore` after calling any methods of it, which will cause unpredictable problems.
The new instances of the `TGStore` should only be created by calling the `New`.
func New ¶
func New() *TGStore
New returns a new instance of the `TGStore` with default field values.
The `New` is the only function that creates new instances of the `TGStore` and keeps everything working.
func (*TGStore) Append ¶
func (tgs *TGStore) Append( ctx context.Context, id string, key []byte, content io.Reader, ) (*Object, error)
Append appends the content to the object targeted by the id.
The lenth of the key must be 16.
func (*TGStore) Download ¶
Download downloads the object targeted by the id from the cloud. It returns `os.ErrNotExist` if not found.
The lenth of the key must be 16.