Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix large file read #2464

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 18 additions & 5 deletions examples/client/node.js/storeBlob.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ const token = 'API_KEY' // your API key from https://nft.storage/manage

async function main() {
const storage = new NFTStorage({ endpoint, token })
const data = await fs.promises.readFile('pinpie.jpg')
const cid = await storage.storeBlob(new Blob([data]))
console.log({ cid })
const status = await storage.status(cid)
console.log(status)
let data = ""
const readStream = fs.createReadStream('pinpie.jpg')
// on data will receive data from the stream and concatenate it to the variable data
readStream.on('data', (chunk) => {
data += chunk
})
// on end will finish the stream
readStream.on('end', async () => {
const cid = await storage.storeBlob(new Blob([data]))
console.log({ cid })
const status = await storage.status(cid)
console.log(status)
})
// on error will show what happened if something goes wrong
readStream.on('error', (error) => {
console.log({ error })
})

}
main()
Loading