Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaydubina committed Feb 22, 2024
1 parent ecda09a commit 8d8a378
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ Efficient reader for large S3 files.
* zero-memory copy
* early HTTP Body termination

```go
s3client := s3.New(session.Must(session.NewSession(
aws.NewConfig().WithRegion("ap-southeast-1"),
)))

r := awss3reader.NewS3ReadSeeker(
s3client,
"nikolaydubina-blog-public",
"videos/2024-02-22.mov",
awss3reader.FixedChunkSizePolicy{Size: 1 << 20 * 40},
)
defer r.Close()

r.Seek(100, io.SeekCurrent)

res, err := io.ReadAll(r)
```

#### Related Work

* https://github.com/yacchi/s3-fast-reader — provides `io.Reader` interface, focuses on connection pool and parallelism, uses mocks for tests
Expand Down
21 changes: 21 additions & 0 deletions aws_s3_reader_seeker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,24 @@ func TestS3ReadSeeker_NotFoundObject(t *testing.T) {
t.Errorf("expected no error")
}
}

func ExampleS3ReadSeeker() {
s3client := s3.New(session.Must(session.NewSession(
aws.NewConfig().WithRegion("ap-southeast-1"),
)))

r := awss3reader.NewS3ReadSeeker(
s3client,
"nikolaydubina-blog-public",
"videos/2024-02-22.mov",
awss3reader.FixedChunkSizePolicy{Size: 1 << 20 * 40},
)
defer r.Close()

r.Seek(100, io.SeekCurrent)
res, err := io.ReadAll(r)

if err != nil || len(res) == 0 {
panic(err)
}
}

0 comments on commit 8d8a378

Please sign in to comment.