Home

Awesome

ls-chunk-store travis npm downloads

Greenkeeper badge

Browser localStorage chunk store that is abstract-chunk-store compliant

abstract chunk store

Features

Install

npm install ls-chunk-store

####You can also use the browserified version from jsDelivr:

<script src="https://cdn.jsdelivr.net/ls-chunk-store/latest/ls-chunk-store.min.js"></script>

Build

The following command will build ls-chunk-store.min.js in the dist folder

npm run-script build

The following command will build ls-chunk-store.js in the root folder

npm run-script build-dev

Usage

Generate random prefix

var LSChunkStore = require('ls-chunk-store')

var chunks = new LSChunkStore(10)

Use specified prefix

var LSChunkStore = require('ls-chunk-store')

var chunks = new LSChunkStore(10, {
  prefix: 'myFile.txt'
})

put, get, close, destroy

chunks.put(0, new Buffer('0123456789'), function (err) {
  if (err) throw err

  chunks.get(0, function (err, chunk) {
    if (err) throw err
    console.log(chunk) // '0123456789' as a buffer

    chunks.close(function (err) {
      if (err) throw err
      console.log('storage is closed')

      chunks.destroy(function (err) {
        if (err) throw err
        console.log('files is deleted')
      })
    })
  })
})

License

MIT. Copyright (c) Diego Rodríguez Baquero.