Struct: s3manager.PooledBufferedReadFromProvider

import "../ibm-cos-sdk-go/service/s3/s3manager"

Overview

PooledBufferedReadFromProvider is a WriterReadFromProvider that uses a sync.Pool to manage allocation and reuse of *bufio.Writer structures.

Implemented Interfaces

s3crypto.Cipher, s3manager.ReadSeekerWriteTo, s3manager.WriterReadFrom, s3manager.WriterReadFromProvider

Constructor Functions collapse

Method Summary collapse

Function Details

func NewPooledBufferedWriterReadFromProvider(size int) *PooledBufferedReadFromProvider

NewPooledBufferedWriterReadFromProvider returns a new PooledBufferedReadFromProvider Size is used to control the size of the underlying *bufio.Writer created for calls to GetReadFrom.



48
49
50
51
52
53
54
55
56
57
58
59
60
// File 'service/s3/s3manager/writer_read_from.go', line 48

func NewPooledBufferedWriterReadFromProvider(size int) *PooledBufferedReadFromProvider { if size < int(32*sdkio.KibiByte) { size = int(64 * sdkio.KibiByte) } return &PooledBufferedReadFromProvider{ pool: sync.Pool{ New: func() interface{} { return &bufferedReadFrom{bufferedWriter: bufio.NewWriterSize(nil, size)} }, }, } }

Method Details

func (p *PooledBufferedReadFromProvider) GetReadFrom(writer io.Writer) (r WriterReadFrom, cleanup func())

GetReadFrom takes an io.Writer and wraps it with a type which satisfies the WriterReadFrom interface/ Additionally a cleanup function is provided which must be called after usage of the WriterReadFrom has been completed in order to allow the reuse of the *bufio.Writer



65
66
67
68
69
70
71
72
73
74
// File 'service/s3/s3manager/writer_read_from.go', line 65

func (p *PooledBufferedReadFromProvider) GetReadFrom(writer io.Writer) (r WriterReadFrom, cleanup func()) { buffer := p.pool.Get().(*bufferedReadFrom) buffer.Reset(writer) r = buffer cleanup = func() { buffer.Reset(nil) // Reset to nil writer to release reference p.pool.Put(buffer) } return r, cleanup }