https://github.com/alevsk/downploader
A small nodejs library providing utility methods for download and upload files through http(s)
https://github.com/alevsk/downploader
file-download file-upload http https nodejs stream
Last synced: 2 months ago
JSON representation
A small nodejs library providing utility methods for download and upload files through http(s)
- Host: GitHub
- URL: https://github.com/alevsk/downploader
- Owner: Alevsk
- License: mit
- Created: 2017-02-05T09:29:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-05T22:01:40.000Z (about 9 years ago)
- Last Synced: 2025-09-06T10:32:36.623Z (7 months ago)
- Topics: file-download, file-upload, http, https, nodejs, stream
- Language: JavaScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
DownPloader
=========
A small nodejs library providing utility methods for download and upload files through http(s)
## Installation
```
npm install --save downploader
```
## Usage examples
#### Download
```
var fs = require('fs');
var dp = require('downploader');
var download = dp.download;
download("https://website.com/image.jpg", (err, data) => {
if(!err) {
fs.writeFileSync('image.jpg', data.read());
}
});
```
#### Upload
```
var fs = require('fs');
var Stream = require('stream').Transform;
var dp = require('downploader');
var upload = dp.upload;
var file = "image.jpg";
var readStream = fs.createReadStream(file);
var bytes = new Stream();
readStream.on('data', function (chunk) {
bytes.push(chunk);
});
readStream.on('error', function (err) {
console.log(err);
});
readStream.on('end', function () {
upload(bytes, "http://localhost/", (err, data) => {
if(err) {
console.log(err);
} else {
console.log(data.read())
}
});
});
```
## Tests
```
$ while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; } | sudo nc -l 80; done // start a simple http server for test upload
$ npm test
```
## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style.
Add unit tests for any new or changed functionality. Lint and test your code.
## Release History
* 0.1.0 Initial release