question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with binary files

See original GitHub issue

Hi,

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:open
  • Created 6 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jacktuckcommented, Feb 20, 2018

Ah so you just want buffer?

require('r2').get('http://ipv4.download.thinkbroadband.com/5MB.zip').response.then(res => res.buffer()).then(console.log)
Promise {
  <pending>,
  domain:
   Domain {
     domain: null,
     _events: { error: [Function: debugDomainError] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] } }
> <Buffer 79 99 f5 09 c5 c2 c8 4e 36 f7 44 2e ce ee 79 2d 14 49 55 cd 50 66 dd 85 8c 56 d3 2e eb 28 d8 55 4c 46 7c 4f 97 a7 2d a8 21 b4 26 9e e8 51 e5 36 40 25 ... >

that work for you?

1reaction
DevBrentcommented, Aug 24, 2018

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found