Skip to content

Commit

Permalink
fix: encode NFT in nodejs 20
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Jul 20, 2023
1 parent dd2ad64 commit 1eb2dba
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/client/src/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,16 @@ export class Token {
// @ts-ignore blob may be a File!
const name = blob.name || 'blob'
/** @type {import('./platform.js').ReadableStream} */
const content = blob.stream()
let content
// FIXME: should not be necessary to await arrayBuffer()!
// Node.js 20 hangs reading the stream (it never ends) but in
// older node versions and the browser it is fine to use blob.stream().
/* c8 ignore next 3 */
if (parseInt(globalThis.process?.versions?.node) > 18) {
content = new Uint8Array(await blob.arrayBuffer())
} else {
content = blob.stream()
}
const { root: cid } = await pack({
input: [{ path: name, content }],
blockstore,
Expand Down

0 comments on commit 1eb2dba

Please sign in to comment.