Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/terkelg/hent
A small utility to fetch remote files into buffers
https://github.com/terkelg/hent
buffers download fetch files get request
Last synced: 3 months ago
JSON representation
A small utility to fetch remote files into buffers
- Host: GitHub
- URL: https://github.com/terkelg/hent
- Owner: terkelg
- License: mit
- Created: 2019-11-03T19:33:35.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-10T20:43:10.000Z (about 5 years ago)
- Last Synced: 2024-07-20T12:22:30.602Z (4 months ago)
- Topics: buffers, download, fetch, files, get, request
- Language: JavaScript
- Homepage:
- Size: 39.1 KB
- Stars: 23
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# hent [![build status](https://badgen.now.sh/github/status/terkelg/hent)](https://github.com/terkelg/hent/actions) [![codecov](https://badgen.now.sh/codecov/c/github/terkelg/hent)](https://codecov.io/gh/terkelg/hent)
> Tiny utility to fetch remote files into buffers
hent is a small, promise based, utility to download remote files into nodejs buffers.
Protocol and redirects are automatically handled for you.## Features
- Promise based
- Supports HTTP and HTTPS protocols
- Follow redirects
- Dependency freeAdditionally, this module is delivered as:
* **ES Module**: [`dist/hent.mjs`](https://unpkg.com/hent/dist/hent.mjs)
* **CommonJS**: [`dist/hent.js`](https://unpkg.com/hent/dist/hent.js)## Install
```
$ npm install --save hent
```## Usage
```js
import hent from 'hent';const {buffer} = await hent('https://example.com/dog.jpeg');
// access response object
const {res, buffer} = await hent('https://example.com/cat.png');// that's it!
```## API
### hent(url, [opts])
Returns: `Promise `The returned object has two properties: `buffer` and `res`.
- `buffer` is the downloaded file as a [Buffer](https://nodejs.org/api/buffer.html).
- `res` is the node [response](https://nodejs.org/api/http.html#http_class_http_incomingmessage) used to access response status, headers and data.> **fyi**: hent is a danish word and means fetch.
### url
Type: `String`URL to the resource you want to download.
Protocol is automatically detected.### opts
Type: `Object`Optional options object passed to [`http.get`](https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_http_get_options_callback).
Use this to define custom headers etc.## License
MIT © [Terkel Gjervig](https://terkel.com)