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.

Downloading binary data

See original GitHub issue

Could you please document somewhere the function at https://github.com/visionmedia/superagent/blob/054782dfaa3f0fd360411be0cbd0f8319d8a75b9/lib/node/index.js#L346? It is tremendously useful if you just want to download binary data. You can use it like this:

var stream = fs.createWriteStream('path/to/my/file.zip');

request.get('http://example.com/file.zip').pipe(stream);

Note: IT does NOT work if you use the Reponse#pipe() method. That method only produces garbage.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
sebastialonsocommented, Jan 31, 2018

Thanks for your reply @kornelski Yesterday I lost all my afternoon trying to trigger the error event on the pipe, forcing a 401 on my request, so I can say with a very high degree of confidence that the event it’s either not being fired by the request error, or it’s not working.

return new Promise((resolve, reject) => {
    stream.on("finish", () => {
      console.log("File saved")
      resolve(stream.path);
    });
    stream.on("error", (err) => {
      console.log("error in request")
    })
  });
0reactions
kornelskicommented, Jan 31, 2018

You can’t directly. You have to call either .pipe() or .then/.end() first to make the request.

There’s response event which lets you inspect the headers as soon as they arrive. Then you can unpipe?

Also with the pipe you should get error event on the pipe.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Uploading and Downloading Binary Data
Android Uploading and Downloading Binary Data. You can upload and download binary data to the GameSparks platform in two ways: Manually; From the...
Read more >
Uploading and Download Binary Data - Juniper Networks
Uploading and Downloading Binary Data. This topic explains how to test REST APIs that upload and download binary data using the SDK REST...
Read more >
Downloading binary files - Thomas Levine
Downloading binary files. Binary files might seem scary if you're used to looking at text. They might be even scarier if they're floating...
Read more >
Android How to - Download Binary Data from the web
The following code shows how to Download Binary Data from the web. Example. Add the following statement to the AndroidManifest.xml file: <?xml version="1.0" ......
Read more >
Download Binary Data with different types - OutSystems
Download Binary Data with different types ... I have a binary list for my web application, and I want to download the file...
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