Skip to content

Commit 8d8a378

Browse files
committed
doc
1 parent ecda09a commit 8d8a378

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ Efficient reader for large S3 files.
99
* zero-memory copy
1010
* early HTTP Body termination
1111

12+
```go
13+
s3client := s3.New(session.Must(session.NewSession(
14+
aws.NewConfig().WithRegion("ap-southeast-1"),
15+
)))
16+
17+
r := awss3reader.NewS3ReadSeeker(
18+
s3client,
19+
"nikolaydubina-blog-public",
20+
"videos/2024-02-22.mov",
21+
awss3reader.FixedChunkSizePolicy{Size: 1 << 20 * 40},
22+
)
23+
defer r.Close()
24+
25+
r.Seek(100, io.SeekCurrent)
26+
27+
res, err := io.ReadAll(r)
28+
```
29+
1230
#### Related Work
1331

1432
* https://github.com/yacchi/s3-fast-reader — provides `io.Reader` interface, focuses on connection pool and parallelism, uses mocks for tests

aws_s3_reader_seeker_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,24 @@ func TestS3ReadSeeker_NotFoundObject(t *testing.T) {
206206
t.Errorf("expected no error")
207207
}
208208
}
209+
210+
func ExampleS3ReadSeeker() {
211+
s3client := s3.New(session.Must(session.NewSession(
212+
aws.NewConfig().WithRegion("ap-southeast-1"),
213+
)))
214+
215+
r := awss3reader.NewS3ReadSeeker(
216+
s3client,
217+
"nikolaydubina-blog-public",
218+
"videos/2024-02-22.mov",
219+
awss3reader.FixedChunkSizePolicy{Size: 1 << 20 * 40},
220+
)
221+
defer r.Close()
222+
223+
r.Seek(100, io.SeekCurrent)
224+
res, err := io.ReadAll(r)
225+
226+
if err != nil || len(res) == 0 {
227+
panic(err)
228+
}
229+
}

0 commit comments

Comments
 (0)