cached-downloader

1.0.6 • Public • Published

CachedDownloader

Module that downloads over http/https and keeps the file in local cache. Items in cache can be assigned references and will not be deleted as long as the reference is active. If an item is dereferenced, TTL property will decide when the file is deleted. Cache is persisted in leveldb.

Install

npm install cached-downloader

Example

const Downloader = require('./cached-downloader');

const downloader = new Downloader({ localDirectory: '/var/tmp/downloader', ttl: 5000, sweep: 2000 });
downloader.on('error', err => console.error(err));
downloader.on('remove', item => console.log('item was removed from cache:', item));
downloader.on('progress', progress => console.log(progress));

const url = 'https://www.thomann.de/pics/bdb/147236/10085220_800.jpg';
downloader.init()
  .then(() => {
    // Download image and assign "bongos" as reference
    downloader.download(url, null, 'bongos')
    .then((filename) => {
      console.log('available @', filename);

      // clear the "bongos" reference, item will be discarded according to TTL
      downloader.clearRef('bongos');
    });
  });


Readme

Keywords

none

Package Sidebar

Install

npm i cached-downloader

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

19.7 kB

Total Files

17

Last publish

Collaborators

  • delphibob