Skip to content

Commit

Permalink
docs: Slightly expand the usage examples in the README
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Feb 8, 2024
1 parent 911158e commit f078b71
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ const s3client = new S3Client({
pathStyle: false,
});

// Log data about each object found under the 'data/concepts/' prefix:
for await (const obj of s3client.listObjects({ prefix: "data/concepts/" })) {
console.log(obj);
}

// Or, to get all the keys (paths) as an array:
const keys = await Array.fromAsync(s3client.listObjects(), (entry) => entry.key);
```

Upload a file to a local MinIO server:
Expand All @@ -70,6 +74,14 @@ const s3client = new S3Client({

// Upload a file:
await s3client.putObject("test.txt", "This is the contents of the file.");

// Now download it
const result = await s3client.getObject("test.txt");
// and stream the results to a local file:
const localOutFile = await Deno.open("test-out.txt", {write: true, createNew: true});
await result.body!.pipeTo(localOutFile.writable);
// or instead of streaming, you can consume the whole file into memory by awaiting
// result.text(), result.blob(), result.arrayBuffer(), or result.json()
```

For more examples, check out the tests in [`integration.ts`](./integration.ts)
Expand Down

0 comments on commit f078b71

Please sign in to comment.