Struct: aws.WriteAtBuffer

import "../ibm-cos-sdk-go/aws"

Overview

A WriteAtBuffer provides a in memory buffer supporting the io.WriterAt interface Can be used with the s3manager.Downloader to download content to a buffer in memory. Safe to use concurrently.

Implemented Interfaces

s3crypto.Cipher, s3manager.ReadSeekerWriteTo, awserr.UnmarshalError, s3manager.WriterReadFrom

Structure Field Summary collapse

Constructor Functions collapse

Method Summary collapse

Structure Field Details

GrowthCoeff float64

GrowthCoeff defines the growth rate of the internal buffer. By default, the growth rate is 1, where expanding the internal buffer will allocate only enough capacity to fit the new expected length.

Function Details

func NewWriteAtBuffer(buf []byte) *WriteAtBuffer

NewWriteAtBuffer creates a WriteAtBuffer with an internal buffer provided by buf.



175
176
177
// File 'aws/types.go', line 175

func NewWriteAtBuffer(buf []byte) *WriteAtBuffer { return &WriteAtBuffer{buf: buf} }

Method Details

func (b *WriteAtBuffer) Bytes() []byte

Bytes returns a slice of bytes written to the buffer.



203
204
205
206
207
// File 'aws/types.go', line 203

func (b *WriteAtBuffer) Bytes() []byte { b.m.Lock() defer b.m.Unlock() return b.buf }

func (b *WriteAtBuffer) WriteAt(p []byte, pos int64) (n int, err error)

WriteAt writes a slice of bytes to a buffer starting at the position provided The number of bytes written will be returned, or error. Can overwrite previous written slices if the write ats overlap.



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// File 'aws/types.go', line 182

func (b *WriteAtBuffer) WriteAt(p []byte, pos int64) (n int, err error) { pLen := len(p) expLen := pos + int64(pLen) b.m.Lock() defer b.m.Unlock() if int64(len(b.buf)) < expLen { if int64(cap(b.buf)) < expLen { if b.GrowthCoeff < 1 { b.GrowthCoeff = 1 } newBuf := make([]byte, expLen, int64(b.GrowthCoeff*float64(expLen))) copy(newBuf, b.buf) b.buf = newBuf } b.buf = b.buf[:expLen] } copy(b.buf[pos:], p) return pLen, nil }