GithubHelp home page GithubHelp logo

isabella232 / fs-chunk-store Goto Github PK

View Code? Open in Web Editor NEW

This project forked from webtorrent/fs-chunk-store

0.0 0.0 0.0 76 KB

Filesystem (fs) chunk store that is abstract-chunk-store compliant

License: MIT License

JavaScript 100.00%

fs-chunk-store's Introduction

fs-chunk-store travis npm downloads javascript style guide

Filesystem (fs) chunk store that is abstract-chunk-store compliant

abstract chunk store

Install

npm install fs-chunk-store

Usage

Back the store with a single file

var FSChunkStore = require('fs-chunk-store')

var chunks = new FSChunkStore(10, {
  path: '/tmp/my_file', // optional: path to file (default: temp file will be used)
  length: 100 // optional: file length in bytes (default: file expands based on `put`s)
})

Back the store with multiple files

var FSChunkStore = require('fs-chunk-store')

var chunks = new FSChunkStore(10, {
  files: [
    { path: 'folder/file1.txt', length: 12 },
    { path: 'folder/file2.txt', length: 8 },
    { path: 'folder/file3.txt', length: 30 }
  ],
  path: 'C:/user/' // optional: if specified the file paths will be treated as relative, not absolute
})

Specifying a path to the store will create a folder in that path, and on destroy, will delete the folder along with all it's contents

put, get, close, destroy

chunks.put(0, Buffer.from('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('/tmp/my_file file descriptor is closed')

      chunks.destroy(function (err) {
        if (err) throw err
        console.log('/tmp/my_file file is deleted')
      })
    })
  })
})

License

MIT. Copyright (c) Feross Aboukhadijeh.

fs-chunk-store's People

Contributors

blissland avatar diegorbaquero avatar feross avatar greenkeeper[bot] avatar greenkeeperio-bot avatar jimmywarting avatar linusu avatar renovate[bot] avatar semantic-release-bot avatar thaunknown avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.