0.1.0 • Published 7 years ago
file-to-npm-cache v0.1.0
file-to-npm-cache
Store a file in the npm cache directory
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');
// <Buffer ... a gzipped tarball of my-file.txt ...>
})();Installation
npm install file-to-npm-cacheAPI
const fileToNpmCache = require('file-to-npm-cache');fileToNpmCache(path, key , options)
path: string (a file path)
key: string (a unique key of a cacache-based cache)
options: Object (cacache.put() options)
Return: Promise<Object>
It compresses a file as a gzipped tar, stores 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.
(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 © 2018 Shinnosuke Watanabe