Closed mreis1 closed 4 years ago
This is by design and it's documented [1]. Read does not guarantee to fully read in one call. You can continue calling read.
This works like FB API and like file systems API. Read returns the number of bytes read and you should continue calling it.
[1]
* Reads data from the blob and return the number of bytes read or -1 for end-of-stream.
* The number of bytes read may be less than the buffer' size while more data to be read exists.
Here's the sample code with annotations
` const blob = results[2][0] as Blob; // @todo Prevent segfault from occurring if blob column is not valid. // Example: const blob = results[0] as Blob; should be const blob = results[0][0] as Blob; // +when invalid, segfault is crashes the app const blobStream = await attachment.openBlob(transaction, blob); let len = await blobStream.length; const buffer = Buffer.alloc(len);
`