Closed
Description
What is the problem this feature will solve?
As of now, the Blob
class only supports data in memory while the spec allows it to be both memory and file based. This has the possibility to use up a lot of memory when writing a lot of data. An example of this would be in the motivator for this change: undici's multipart/form-data support where it stores the entire response file in memory (https://github.com/nodejs/undici/pull/1606/files#diff-bd6db9a8bceb4e9fce3f93ba5284c81f46a44a1187909e8609006e1efeab2570R427).
What is the feature you are proposing to solve the problem?
Adding support to Blob
to work either off of memory or a file.
- C++ side: keep the current
Blob
class the same and make a separate class calledFileBlob
.- Implements the exact same api, only difference is it would use a file (through
std::fstream
or something) rather than a vector.
- Implements the exact same api, only difference is it would use a file (through
- Javascript side: No breaking changes to the existing Javascript api. It would use the exact same
Blob
class that already exists, just with its native handle pointing to aFileBlob
instance rather thanBlob
. - Javascript side: Create method
fs.getFileBlob('some-file-path.txt')
to get aBlob
instance that is file-based- If no file path is provided, a file is created in the temp directory under some random name
I'm currently working on implementing this and opened this issue to get some feedback on it.
cc @mcollina
What alternatives have you considered?
No response