{"modulePath":"github.com/foxcpp/maddy","version":"v0.3.3","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package buffer\n\nThe buffer package provides utilities for temporary storage (buffering) of large blobs.\n\n## Types\n\n```go\ntype Buffer interface {\n\t// Open creates new Reader reading from the underlying storage.\n\tOpen() (io.ReadCloser, error)\n\n\t// Len reports the length of the stored blob.\n\t//\n\t// Notably, it indicates the amount of bytes that can be read from the\n\t// newly created Reader without hiting io.EOF.\n\tLen() int\n\n\t// Remove discards buffered body and releases all associated resources.\n\t//\n\t// Multiple Buffer objects may refer to the same underlying storage.\n\t// In this case, care should be taken to ensure that Remove is called\n\t// only once since it will discard the shared storage and invalidate\n\t// all Buffer objects using it.\n\t//\n\t// Readers previously created using Open can still be used, but\n\t// new ones can't be created.\n\tRemove() error\n}\n```\nBuffer interface represents abstract temporary storage for blobs.\n\nThe Buffer storage is assumed to be immutable. If any modifications are made - new storage location should be used for them. This is important to ensure goroutine-safety.\n\nSince Buffer objects require a careful management of lifetimes, here is the convention: Its always creator responsibility to call Remove after Buffer is no longer used. If Buffer object is passed to a function - it is not guaranteed to be valid after this function returns. If function needs to preserve the storage contents, it should \"re-buffer\" it either by reading entire blob and storing it somewhere or applying implementation-specific methods (for example, the FileBuffer storage may be \"re-buffered\" by hard-linking the underlying file).\n\n```go\nfunc BufferInFile(r io.Reader, dir string) (Buffer, error)\n```\nBufferInFile is a convenience function which creates FileBuffer with underlying file created in the specified directory with the random name.\n\n```go\nfunc BufferInMemory(r io.Reader) (Buffer, error)\n```\nBufferInMemory is a convenience function which creates MemoryBuffer with contents of the passed io.Reader.\n\n```go\ntype BytesReader struct {\n\t*bytes.Reader\n\t// contains filtered or unexported fields\n}\n```\nBytesReader is a wrapper for bytes.Reader that stores the original \\[]byte value and allows to retrieve it.\n\nIt is meant for passing to libraries that expect a io.Reader but apply certain optimizations when the Reader implements Bytes() interface.\n\n```go\nfunc NewBytesReader(b []byte) BytesReader\n```\n\n```go\nfunc (br BytesReader) Bytes() []byte\n```\nBytes returns the unread portion of underlying slice used to construct BytesReader.\n\n```go\nfunc (br BytesReader) Close() error\n```\nClose is a dummy method for implementation of io.Closer so BytesReader can be used in MemoryBuffer directly.\n\n```go\nfunc (br BytesReader) Copy() BytesReader\n```\nCopy returns the BytesReader reading from the same slice as br at the same position.\n\n```go\ntype FileBuffer struct {\n\tPath string\n\n\t// LenHint is the size of the stored blob. It can\n\t// be set to avoid the need to call os.Stat in the\n\t// Len() method.\n\tLenHint int\n}\n```\nFileBuffer implements Buffer interface using file system.\n\n```go\nfunc (fb FileBuffer) Len() int\n```\n\n```go\nfunc (fb FileBuffer) Open() (io.ReadCloser, error)\n```\n\n```go\nfunc (fb FileBuffer) Remove() error\n```\n\n```go\ntype MemoryBuffer struct {\n\tSlice []byte\n}\n```\nMemoryBuffer implements Buffer interface using byte slice.\n\n```go\nfunc (mb MemoryBuffer) Len() int\n```\n\n```go\nfunc (mb MemoryBuffer) Open() (io.ReadCloser, error)\n```\n\n```go\nfunc (mb MemoryBuffer) Remove() error\n```\n\n","path":"github.com/foxcpp/maddy/internal/buffer","name":"buffer","synopsis":"The buffer package provides utilities for temporary storage (buffering) of large blobs.","isRedistributable":true}
