1/*2Maddy Mail Server - Composable all-in-one email server.3Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors45This program is free software: you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation, either version 3 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program. If not, see <https://www.gnu.org/licenses/>.17*/1819// The buffer package provides utilities for temporary storage (buffering)20// of large blobs.21package buffer2223import (24 "io"25)2627// Buffer interface represents abstract temporary storage for blobs.28//29// The Buffer storage is assumed to be immutable. If any modifications30// are made - new storage location should be used for them.31// This is important to ensure goroutine-safety.32//33// Since Buffer objects require a careful management of lifetimes, here34// is the convention: Its always creator responsibility to call Remove after35// Buffer is no longer used. If Buffer object is passed to a function - it is not36// guaranteed to be valid after this function returns. If function needs to preserve37// the storage contents, it should "re-buffer" it either by reading entire blob38// and storing it somewhere or applying implementation-specific methods (for example,39// the FileBuffer storage may be "re-buffered" by hard-linking the underlying file).40type Buffer interface {41 // Open creates new Reader reading from the underlying storage.42 Open() (io.ReadCloser, error)4344 // Len reports the length of the stored blob.45 //46 // Notably, it indicates the amount of bytes that can be read from the47 // newly created Reader without hiting io.EOF.48 Len() int4950 // Remove discards buffered body and releases all associated resources.51 //52 // Multiple Buffer objects may refer to the same underlying storage.53 // In this case, care should be taken to ensure that Remove is called54 // only once since it will discard the shared storage and invalidate55 // all Buffer objects using it.56 //57 // Readers previously created using Open can still be used, but58 // new ones can't be created.59 Remove() error60}