-
-
Notifications
You must be signed in to change notification settings - Fork 243
Buffer slicing not working when passed to a browser XHR #46
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
Comments
500be9e is referring to the Node.js behavior of slice where both the original buffer and the slice are pointing at the exact same memory region, so modifying one will also modify the other. Since the fallback uses a copy approach then modifying the copy will not modify the original, so @feross is warning that you can't rely on that. It seems that the behavior that we were seeing is that the slice was not being respected when the sliced buffer was passed to the XHR, as the XHR was uploading the entire source buffer, rather than just the sliced view. This obviously differs from the Node.js implementation where if you pass a sliced view of a buffer to a POST request is only uploads the sliced section, rather than the entire buffer. |
Ah, okay I re-read it, you're right. That's sort of addressing the opposite situation, where you want to keep a reference to the parent through a slice, and the browser doesn't support that. In our situation, the browser implementation (I tested on the latest version of Chrome and Firefox, on Ubuntu) of |
@nathanpeck is right – the broken The object returned from the Otherwise, this sounds like a spec and/or browser bug. |
This might well be it. From if (httpRequest.body && typeof httpRequest.body.buffer === 'object') {
xhr.send(httpRequest.body.buffer); // typed arrays sent as ArrayBuffer
} else {
xhr.send(httpRequest.body);
} The whole point of this block is to make sure to call the |
See: http://updates.html5rocks.com/2012/07/Arrived-xhr-send-ArrayBufferViews |
OK, so it seems clear now that the issue is not in the Am I correct in thinking that what I should do next is send an issue to |
That sounds like a good plan to me. Feel free to reference the issue you open here, for posterity. I suspect that trying to send an object that |
This is being addressed in aws/aws-sdk-js#391, for those interested. |
I ran into an issue, documented in nathanpeck/s3-upload-stream#20, where a Buffer that had been sliced and then passed onto the browser's native XHR object wasn't having its sliced view respected.
It looks like you might have already addressed and documented this in 500be9e? If so, it might be worth rephrasing with less low-level terminology or something? I think I understand what "parent tracking" means, and that this is the issue I'm seeing, but I'm not sure.
The text was updated successfully, but these errors were encountered: