I'm trying to convert an arraybuffer of a file to a readable stream in Typescript but when i'm trying to create a new ReadableStream variable I obtain this error:
UnhandledPromiseRejectionWarning: ReferenceError: ReadableStream is not defined
What is the problem ? This is my code :
export function ReadableBufferStream(ab: ArrayBuffer) {
return new ReadableStream({
start(controller) {
controller.enqueue(ab)
controller.close()
}
})
}
export async function putFileToIPFS(file:ArrayBuffer): Promise<string>{
const readableStream = ReadableBufferStream(file)
let cid ;
try {
console.log("PRINT BEFORE PIN")
cid = await pinata.pinFileToIPFS(readableStream)
console.log(cid)
}
catch (error) { console.error(error);}
return cid['IpfsHash']
}
does anyone know how to help me? I start from a buffer array and would like to be able to get a ReadableStream to be able to load it on IPFS. A thousand thanks
Can you try this(importing
ReadableStream
fromnode
types)...