Documentation ¶
Index ¶
- Variables
- func NewNWriter(onChunk func(chunk *Attachment), chunkSize int, mgr *Manager) io.WriteCloser
- func NewReader(chunks []Attachment, pos int64, arc *Manager) (io.ReadCloser, error)
- func NewWriter(onChunk func(chunk *Attachment), chunkSize int, mgr *Manager) io.WriteCloser
- type Attachment
- type Manager
- type Message
- type NWriter
- type Reader
- type Rest
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyClosed = errors.New("already closed")
ErrAlreadyClosed is returned when the reader/writer is already closed
var ErrClosed = errors.New("is closed")
ErrClosed is returned when a writer or reader is closed and caller is trying to read or write
var ErrInvalidWebhookURL = errors.New("invalid webhook URL")
ErrInvalidWebhookURL is the error returned for an invalid webhook URL.
var WebhookURLRegex = regexp.MustCompile(`^https://(?:[a-zA-Z]+\.)?discord\.com/api/webhooks/\d+/[a-zA-Z0-9_-]+$`)
WebhookURLRegex is the regular expression pattern to validate a webhook URL.
Functions ¶
func NewNWriter ¶
func NewNWriter(onChunk func(chunk *Attachment), chunkSize int, mgr *Manager) io.WriteCloser
func NewReader ¶
func NewReader(chunks []Attachment, pos int64, arc *Manager) (io.ReadCloser, error)
NewReader creates new Reader instance which implements io.ReadCloser.
func NewWriter ¶
func NewWriter(onChunk func(chunk *Attachment), chunkSize int, mgr *Manager) io.WriteCloser
NewWriter creates a new Writer with the given chunk Size and manager.
Types ¶
type Attachment ¶
type Attachment struct { URL string `json:"url"` // URL where the data is stored Size int `json:"size"` // Size of the data Start int64 // Start position of the data in the overall data sequence End int64 // End position of the data in the overall data sequence }
Attachment represents a Discord attachment URL and Size
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provides an interface to read and write large files to Discord by splitting the files into smaller chunks, uploading or downloading these chunks through Discord webhooks, and reassembling them into the original files.
func NewManager ¶
NewManager returns a new instance of Manager with specified chunk size and webhook URLs. It initializes a list of webhook rest clients for each webhook URL.
func (*Manager) NewNWriter ¶
func (mgr *Manager) NewNWriter(onChunk func(chunk *Attachment)) io.WriteCloser
NewNWriter creates a new ddrv.NWriter instance that implements an io.WriterCloser. This allows for writing large files to Discord as small, manageable chunks. NWriter buffers bytes into memory and writes data to discord in parallel
func (*Manager) NewReader ¶
func (mgr *Manager) NewReader(chunks []Attachment, pos int64) (io.ReadCloser, error)
NewReader creates a new Reader instance that implements an io.ReaderCloser. This allows for reading large files from Discord that were split into small chunks.
func (*Manager) NewWriter ¶
func (mgr *Manager) NewWriter(onChunk func(chunk *Attachment)) io.WriteCloser
NewWriter creates a new ddrv.Writer instance that implements an io.WriterCloser. This allows for writing large files to Discord as small, manageable chunks.
type Message ¶
type Message struct {
Attachments []Attachment `json:"attachments"`
}
Message represents a Discord message and contains attachments (files uploaded within the message).
type NWriter ¶
type NWriter struct {
// contains filtered or unexported fields
}
NWriter implements io.WriteCloser. It streams data in chunks to Discord server channels using webhook NWriter buffers bytes into memory and writes data to discord in parallel at the cost of high-memory usage. expected memory usage - (chunkSize * number of webhooks) + 20% bytes
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a structure that manages the reading of a sequence of Chunks. It reads chunks in order, closing each one after it's Read and moving on to the next.
type Rest ¶
type Rest struct {
// contains filtered or unexported fields
}
Rest represents the Discord webhook REST client.
func (*Rest) CreateAttachment ¶
func (r *Rest) CreateAttachment(reader io.Reader) (*Attachment, error)
CreateAttachment uploads a file to the Discord channel using the webhook.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements io.WriteCloser. It streams data in chunks to Discord server channels using webhook
func (*Writer) Close ¶
Close implements the Close method of io.Closer. It closes the Writer. If the Writer is already closed, Close returns ErrAlreadyClosed.