{"modulePath":"github.com/weiwolves/pkg","version":"v0.0.0-20200322065615-581c8d33cff6","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package bufferpool\n\nPackage bufferpool implements a pool of reusable auto-resizing buffers.\n\n## Functions\n\n```go\nfunc Get() *bytes.Buffer\n```\nGet returns a buffer from the pool.\n\n```go\nfunc GetReader(b []byte) *bytes.Reader\n```\nGet returns a byte reader from the pool.\n\n```go\nfunc New(size int) tank\n```\nNew instantiates a new bytes.Buffer pool with a custom pre-allocated buffer size.\n\n```go\nfunc NewTwin(size int) twinTank\n```\nNewTwin instantiates a new TwinBuffer pool with a custom pre-allocated buffer size. The fields \\`First\\` and \\`Second\\` will have the same size.\n\n```go\nfunc Put(buf *bytes.Buffer)\n```\nPut returns a buffer to the pool. The buffer is reset before it is put back into circulation.\n\n```go\nfunc PutReader(r *bytes.Reader)\n```\nPut returns a byte reader to the pool. The reader is reset before it is put back into circulation.\n\n```go\nfunc PutTwin(buf *TwinBuffer)\n```\nPutTwin returns a twin buffer to the pool. The buffers get reset before they are put back into circulation.\n\n```go\nfunc PutTwinCallBack(buf *TwinBuffer, fn func())\n```\nPutTwinCallBack same as PutTwin but executes fn after buf has been returned into the pool.\n\n\tbuf := twinBuf.Get()\n\tdefer twinBuf.PutCallBack(buf, wg.Done)\n\n## Types\n\n```go\ntype TwinBuffer struct {\n\tFirst  *bytes.Buffer\n\tSecond *bytes.Buffer\n}\n```\nTwinBuffer contains two buffers.\n\n```go\nfunc GetTwin() *TwinBuffer\n```\nGetTwin returns a buffer containing two buffers, \\`First\\` and \\`Second\\`, from the pool.\n\n```go\nfunc (tw *TwinBuffer) CopyFirstToSecond() (n int64, err error)\n```\nCopyFirstToSecond resets the second buffer and copies the content from the first buffer to the second buffer. First buffer gets eventually reset.\n\n```go\nfunc (tw *TwinBuffer) CopySecondToFirst() (n int64, err error)\n```\nCopySecondToFirst resets the first buffer and copies the content from the second buffer to the first buffer. Second buffer gets eventually reset.\n\n```go\nfunc (tw *TwinBuffer) Reset()\n```\nReset resets both buffers.\n\n```go\nfunc (tw *TwinBuffer) String() string\n```\nString prints the buffers content for debug purposes.\n\n```go\nfunc (tw *TwinBuffer) Write(p []byte) (n int, err error)\n```\nWrite writes to both buffers one after another.\n\n","path":"github.com/weiwolves/pkg/util/bufferpool","name":"bufferpool","synopsis":"Package bufferpool implements a pool of reusable auto-resizing buffers.","isRedistributable":true}
