Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions docs/build-with-0g/storage-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,23 @@ readableStream.push('Hello, 0G Storage!');
readableStream.push(null);

// Upload using a stream
const streamRoot = await client.uploadStream(readableStream, 'example.
txt');
console.log("Stream uploaded with root hash:", streamRoot);

// Download as a stream
const downloadStream = await client.downloadFileAsStream(streamRoot);
downloadStream.pipe(process.stdout);
try {
const streamRoot = await client.uploadStream(readableStream, 'example.txt');
console.log("Stream uploaded with root hash:", streamRoot);

// Download as a stream
const downloadStream = await client.downloadFileAsStream(streamRoot);
downloadStream
.on('error', (error) => {
console.error('Error during download:', error);
})
.pipe(process.stdout)
.on('error', (error) => {
console.error('Error writing to stdout:', error);
});
} catch (error) {
console.error('Error during upload:', error);
}
```

## Best Practices
Expand Down