Skip to content
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

Drop request and request-promise deps #19

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 48 additions & 40 deletions binstall.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fs = require("fs");
var request = require("request");
var request = require("./request.js");
var tar = require("tar");
var zlib = require("zlib");
var unzip = require("unzip-stream");
Expand Down Expand Up @@ -42,29 +42,32 @@ function untgz(url, path, options) {
reject("Error decompressing " + url + " " + error);
});

request
.get(url, function(error, response) {
if (error) {
reject("Error communicating with URL " + url + " " + error);
return;
}
if (response.statusCode == 404) {
var errorMessage = options.errorMessage || "Not Found: " + url;
var req = request(url, {method: "GET"});

reject(new Error(errorMessage));
return;
}
req.on("response", function(response) {
if (response.statusCode == 404) {
var errorMessage = options.errorMessage || "Not Found: " + url;

if (verbose) {
console.log("Downloading binaries from " + url);
}
throw new Error(errorMessage);
}

response.on("error", function() {
reject("Error receiving " + url);
});
})
.pipe(gunzip)
.pipe(untar);
if (verbose) {
console.log("Downloading binaries from " + url);
}

response.on("error", function() {
reject("Error receiving " + url);
});

response.pipe(gunzip).pipe(untar);
});

req.on("error", function(error) {
reject("Error communicating with URL " + url + " " + error);
return;
});

req.end();
});
}

Expand Down Expand Up @@ -97,28 +100,33 @@ function unzipUrl(url, path, options) {
}
});

request
.get(url, function(error, response) {
if (error) {
reject("Error communicating with URL " + url + " " + error);
return;
}
if (response.statusCode == 404) {
var errorMessage = options.errorMessage || "Not Found: " + url;
var req = request(url, {method: "GET"});

reject(new Error(errorMessage));
return;
}
req.on("response", function(response) {
if (response.statusCode == 404) {
var errorMessage = options.errorMessage || "Not Found: " + url;

if (verbose) {
console.log("Downloading binaries from " + url);
}
reject(new Error(errorMessage));
return;
}

response.on("error", function() {
reject("Error receiving " + url);
});
})
.pipe(writeStream);
if (verbose) {
console.log("Downloading binaries from " + url);
}

response.on("error", function() {
reject("Error receiving " + url);
});

response.pipe(writeStream);
});

req.on("error", function(error) {
reject("Error communicating with URL " + url + " " + error);
return;
});

req.end();
});
}

Expand Down
Loading