Struct: s3manager.BufferedReadSeeker

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

Overview

BufferedReadSeeker is buffered io.ReadSeeker

Implemented Interfaces

s3crypto.Cipher, s3manager.ReadSeekerWriteTo, s3manager.WriterReadFrom

Constructor Functions collapse

Method Summary collapse

Function Details

func NewBufferedReadSeeker(r io.ReadSeeker, b []byte) *BufferedReadSeeker

NewBufferedReadSeeker returns a new BufferedReadSeeker if len(b) == 0 then the buffer will be initialized to 64 KiB.



17
18
19
20
21
22
// File 'service/s3/s3manager/buffered_read_seeker.go', line 17

func NewBufferedReadSeeker(r io.ReadSeeker, b []byte) *BufferedReadSeeker { if len(b) == 0 { b = make([]byte, 64*1024) } return &BufferedReadSeeker{r: r, buffer: b} }

Method Details

func (b *BufferedReadSeeker) Read(p []byte) (n int, err error)

Read will read up len(p) bytes into p and will return the number of bytes read and any error that occurred. If the len(p) > the buffer size then a single read request will be issued to the underlying io.ReadSeeker for len(p) bytes. A Read request will at most perform a single Read to the underlying io.ReadSeeker, and may return < len(p) if serviced from the buffer.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// File 'service/s3/s3manager/buffered_read_seeker.go', line 35

func (b *BufferedReadSeeker) Read(p []byte) (n int, err error) { if len(p) == 0 { return n, err } if b.readIdx == b.writeIdx { if len(p) >= len(b.buffer) { n, err = b.r.Read(p) return n, err } b.readIdx, b.writeIdx = 0, 0 n, err = b.r.Read(b.buffer) if n == 0 { return n, err } b.writeIdx += n } n = copy(p, b.buffer[b.readIdx:b.writeIdx]) b.readIdx += n return n, err }

func (b *BufferedReadSeeker) ReadAt(p []byte, off int64) (int, error)

ReadAt will read up to len(p) bytes at the given file offset. This will result in the buffer being cleared.



73
74
75
76
77
78
79
80
// File 'service/s3/s3manager/buffered_read_seeker.go', line 73

func (b *BufferedReadSeeker) ReadAt(p []byte, off int64) (int, error) { _, err := b.Seek(off, sdkio.SeekStart) if err != nil { return 0, err } return b.Read(p) }

func (b *BufferedReadSeeker) Seek(offset int64, whence int) (int64, error)

Seek will position then underlying io.ReadSeeker to the given offset and will clear the buffer.



63
64
65
66
67
68
69
// File 'service/s3/s3manager/buffered_read_seeker.go', line 63

func (b *BufferedReadSeeker) Seek(offset int64, whence int) (int64, error) { n, err := b.r.Seek(offset, whence) b.reset(b.r) return n, err }