Issues with binary files
See original GitHub issueHi,
I really wanted to use r2
as a modern alternative to request
, but I ran into issues with binary files. When I try to download for example our company logo, it all works fine:
> (async function () { console.log(await require('r2').get('https://wizcorp.jp/images/logo.png').arrayBuffer); console.log('done'); })();
output:
Promise {
<pending>,
domain:
Domain {
domain: null,
_events:
{ removeListener: [Function: updateExceptionCapture],
newListener: [Function: updateExceptionCapture],
error: [Function: debugDomainError] },
_eventsCount: 3,
_maxListeners: undefined,
members: [] } }
> ArrayBuffer { byteLength: 3874 }
done
But on a larger file (not sure if “large” has anything to do with it though), it just sort of hangs there:
(async function () { console.log(await require('r2').get('http://ipv4.download.thinkbroadband.com/5MB.zip').arrayBuffer); console.log('done'); })();
output:
Promise {
<pending>,
domain:
Domain {
domain: null,
_events:
{ removeListener: [Function: updateExceptionCapture],
newListener: [Function: updateExceptionCapture],
error: [Function: debugDomainError] },
_eventsCount: 3,
_maxListeners: undefined,
members: [] } }
>
Replacing .arrayBuffer
with .response
does seem to return a response object of some kind, but I don’t know how to extract data from that:
> (async function () { console.log(await require('r2').get('http://ipv4.download.thinkbroadband.com/5MB.zip').response); console.log('done'); })();
output:
Promise {
<pending>,
domain:
Domain {
domain: null,
_events:
{ removeListener: [Function: updateExceptionCapture],
newListener: [Function: updateExceptionCapture],
error: [Function: debugDomainError] },
_eventsCount: 3,
_maxListeners: undefined,
members: [] } }
> Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]:
{ body:
PassThrough {
_readableState: [ReadableState],
readable: true,
domain: [Domain],
_events: [Object],
_eventsCount: 7,
_maxListeners: undefined,
_writableState: [WritableState],
writable: true,
allowHalfOpen: true,
_transformState: [Object] },
disturbed: false,
error: null },
[Symbol(Response internals)]:
{ url: 'http://ipv4.download.thinkbroadband.com/5MB.zip',
status: 200,
statusText: 'OK',
headers: Headers { [Symbol(map)]: [Object] } } }
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Common Problems with Binary Files
Common Problems with Binary Files ... If the data is expected to fall into a known range of values, then a program can...
Read more >Common Problems with Binary Files
This is a common problem in programming. Some files are many years old and were created with poorly documented programs that ran on...
Read more >Version Control for Binary Files: Your Best Options - Perforce
Challenges of Binary File Management Some of the main challenges in managing and versioning binaries include: You can't merge them, making ...
Read more >Why you should not push binary files to git? And what to do if ...
Today, I'd like to show you one of most common problems when using git and how to solve that problem. Which version control...
Read more >Git is Bad at Binary File Management -- But is it Worse than ...
The problem with git and binary files don't turn out to be practical problems if the repo has only a small number of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah so you just want buffer?
that work for you?
@ronkorving This is related to the use of .clone() in the wrapper r2 has for .text .json .arraybuffer etc. You can
await (await r2(url).response).buffer()
The writestream is paused because the original response object’s readstream never reads any data when we clone in r2. It’s a node-fetch/streams problem but others in the community are working around it by not using clone.
See: https://github.com/mikeal/r2/issues/48#issuecomment-415166175