import util from 'util';
import http from 'http';
function HttpError(status, message) {
Error.apply(this, arguments);
Error.captureStackTrace(this, HttpError);
this.status = status;
this.message = message || http.STATUS_CODES[status] || "Error";
}
util.inherits(HttpError, Error);
HttpError.prototype.name = 'HttpError';
export {HttpError};
let newBuff = Buffer.from('New String');
console.log(newBuff.toString('utf8')); // New String
var StringDecoder = require('string_decoder').StringDecoder;
var d = new StringDecoder('utf8');
var b = Buffer('abc');
console.log(b); // <Buffer 61 62 63>
console.log(d.write(b)); // abc
server.post("/uploads", (req, res) => {
new formidable.IncomingForm()
.parse(req)
.on("file", function(name, file) {
console.log("Got file:", name);
})
.on("field", function(name, field) {
console.log("Got a field:", name);
})
.on("error", function(err) {
next(err);
})
.on("end", function() {
res.end();
});
});
var fs = require("fs"),
request = require("request");
const download = (uri, filename, callback) => {
request.head(uri, (err, res, body) => {
request(uri)
.pipe(fs.createWriteStream(filename))
.on("close", callback);
});
};
download(
"http://fs.moviestape.net/video/1c4ed0ac8b7d5b4de6c5d58e2ea31a63/serials/Narcos/s01/Narcos.S01E01.mp4",
"./downloads/filename.mp4",
() => {
console.log("done");
}
);