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
fs: allow read/write to accept an ArrayBuffer #11641
Conversation
|
Pause on this. It won't work on Windows (ref libuv/libuv#1236 (comment)). So it appears that |
|
@trevnorris are you going to follow up on this? |
|
@BridgeAR Forgot I had started this. It stalled b/c I wanted to see about changing I'll try to get this rebased and fixing again in the near future. Unless you are asking b/c you want to pick this up and run with it. :-) |
|
@trevnorris as time is limited for all of us, I was not planning on following up on this currently. So it would be nice if you find the time to rebase this. In that case this could be properly reviewed. |
|
@BridgeAR Will do. |
fs.read() and fs.write() now accept an ArrayBuffer. Typed Arrays are limited in size by a max index of Smi (0x7fffffff on x64 and 0x3fffffff on ia32). While, in V8, ArrayBuffers are limited to max size_t. Though for practical reasons it would be limited to Number.MAX_SAFE_INTEGER (or approximately 8PB). So now the maximum file size that can be read/written is only limited by the amount of available memory. This presents a problem to fully test because it requires that at least 4GB of memory be available. To implement this, one shortcoming of uv_buf_init() was addressed. The "len" argument is an unsigned int. Whereas the "len" property of a uv_buf_t is a size_t. So len needs to be set manually. Otherwise it could be truncated. PR-URL: nodejs#11641
|
@BridgeAR Has been rebased and running new CI |
|
I think it may make sense to expand this at some point to support any |
|
@jasnell This is about allowing I don’t think the added complexity here justifies the feature (esp. given that it’s perfectly reasonably implementable in userland and not a common use case), but then again it’s not a huge problem either. |
|
Yes, I know. |
I'd like to have full EDIT: I agree that the added complexity sucks, but it's not that much, and if you see a way to simplify it I'll happily update the PR. |
|
@trevnorris what do we need for full |
|
@addaleax read/write is currently broken. Example writing: const fs = require('fs');
const file_path = '/tmp/buf_file.blah';
const buf = Buffer.alloc(require('buffer').kMaxLength, 1);
const fd = fs.openSync(file_path, 'w+');
const written = fs.writeSync(fd, buf, 0, buf.byteLength, 0);
console.log(fs.statSync(file_path).size, buf.byteLength);
// output: 2147479552 2147483647now for reading. first create the file: now reading the file: const fs = require('fs');
const file_path = '/tmp/buf_file.blah';
const buf = Buffer.allocUnsafe(fs.statSync(file_path).size);
const fd = fs.openSync(file_path, 'r+');
const bytes = fs.readSync(fd, buf, 0, buf.byteLength, 0);
console.log(bytes, buf.byteLength);
// output: 2147479552 2147483647We've been ignoring a documented kernel limitation:
This PR fixes that and adds new functionality. EDIT: @addaleax I was taking the opinion that it should always write all the data to the file unless there was an error because I'd expect the same of doing a TCP write, but guess they don't work that way. node is just so cozy and handles all that hard stuff for me so often that I became lazy. |
|
@santigimeno mentioned the libuv bug libuv/libuv#1501 which we'll need to work around. if the libuv fix doesn't land soon i'll change the PR so the maximum data written at a single time is 2GB. |
|
Closing this after having a discussion on IRC. To summarize: I had expected So, instead we'll need a PR for updating the docs with language to clarify that it's the user's responsibility to check the return value and make sure all the data has been read/written. |
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s):
fs
fs.read()andfs.write()now accept anArrayBuffer.Typed Arrays are limited in size by a max index of Smi (
0x7fffffffonx64 and
0x3fffffffon ia32). While, in V8,ArrayBuffers are limited tomax
size_t. Though for practical reasons it would be limited toNumber.MAX_SAFE_INTEGER(or approximately 8PB).So now the maximum file size that can be read/written is only limited by
the amount of available memory. This presents a problem to fully test
because it requires that at least 4GB of memory be available.
To implement this, one shortcoming of
uv_buf_init()was addressed. Thelenargument is an unsigned int. Whereas thelenproperty of auv_buf_tis asize_t. Solenneeds to be set manually. Otherwise itcould be truncated.
CI: https://ci.nodejs.org/job/node-test-commit/8191/