Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/file-to-npm-cache
Store a file in the npm cache directory
https://github.com/shinnn/file-to-npm-cache
cache compression gzip javascript nodejs npm promise tar tgz
Last synced: 27 days ago
JSON representation
Store a file in the npm cache directory
- Host: GitHub
- URL: https://github.com/shinnn/file-to-npm-cache
- Owner: shinnn
- License: isc
- Created: 2018-10-17T03:17:10.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-28T12:34:25.000Z (over 5 years ago)
- Last Synced: 2024-10-16T10:31:46.966Z (29 days ago)
- Topics: cache, compression, gzip, javascript, nodejs, npm, promise, tar, tgz
- Language: JavaScript
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# file-to-npm-cache
[![npm version](https://img.shields.io/npm/v/file-to-npm-cache.svg)](https://www.npmjs.com/package/file-to-npm-cache)
[![Build Status](https://travis-ci.com/shinnn/file-to-npm-cache.svg?branch=master)](https://travis-ci.com/shinnn/file-to-npm-cache)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/file-to-npm-cache.svg)](https://coveralls.io/github/shinnn/file-to-npm-cache?branch=master)Store a file in the [npm cache directory](https://docs.npmjs.com/files/folders#cache)
```javascript
const cacache = require('cacache');
const fileToNpmCache = require('file-to-npm-cache');(async () => {
const cacheInfo = await fileToNpmCache('my-file.txt', 'my-key');
/*=> {
key: 'my-key',
integrity: 'sha512-G31q ... RV3w==',
path: '/Users/shinnn/.npm/_cacache/content-v2/sha512/1b/7d/ ...',
size: 1107,
time: 1539591818472,
metadata: undefined
}*/const {data} = await cacache.get('/Users/shinnn/.npm', 'my-key');
//
})();
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
```
npm install file-to-npm-cache
```## API
```javascript
const fileToNpmCache = require('file-to-npm-cache');
```### fileToNpmCache(*path*, *key* [, *options*])
*path*: `string` (a file path)
*key*: `string` (a unique key of a [cacache](https://github.com/zkat/cacache)-based cache)
*options*: `Object` ([`cacache.put()`](https://github.com/zkat/cacache#put-options) options)
Return: `Promise`It compresses a file as a [gzipped](https://www.gzip.org) [tar](https://www.gnu.org/software/tar/manual/html_node/Standard.html), [stores](https://github.com/zkat/cacache#put-data) it into the npm cache folder and returns a `Promise` for an `Object` of the created cache information.
If the target is not a file, it returns a rejected `Promise`.
```javascript
(async () => {
try {
await fileToNpmCache('/etc', 'key-foo-bar');
} catch (err) {
err.message;
//=> Expected a file path to save it as an npm cache, but the entry at /etc is not a file.
}
})();
```## License
[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe