npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

raid2x

v0.1.24

Published

A Software Raid Algorithm

Downloads

16

Readme

Raid2X

Build Status Deps Status

Raid2X is a software raid algorithm

  • Pure JavaScript
  • Support file Segmentation / Merge
  • Support file Encrypt / Decrypt
  • File would be divided into 2N parts (N mod 2 = 1),and could be recovery by only N + 1 parts

Installing

npm install raid2x

Requires nodejs >= 0.10.x

Usage

Quick Test

var Raid2X = require('raid2x');
var filepath = "/Users/luphia/Documents/Workspace/Playground/logo.png";
var distination = "/Users/luphia/Desktop/";
var r2x = new Raid2X(filepath), r2x1, meta;
r2x.setSliceSize(61440);
meta = r2x.getMeta(true);
r2x1 = new Raid2X(meta);
for(var i = 0; i < meta.sliceCount; i++) {
	r2x1.importShard(r2x.getShard(i));
}
r2x1.save(distination + meta.name);

Initial Raid2X

var Raid2X = require("raid2x");
var r2x = new Raid2X([options]);
  • options - {Buffer|File path|Metadata}

Metadata

You can also export the Metadata from an exist Raid2X over r2x.getMeta()

  • name - [String] name of original file
  • size - [INT] size of original file
  • hash - [String] hash of original file (SHA1 + CRC)
  • encFile - [Boolean] to switch
  • encShard - [Boolean]
  • sliceCount - [INT]
  • sliceSize - [INT]
  • duplicate - [Boolean]
  • shardList - [String Array]

Load file

r2x.readFile("/path/to/your/file.txt", function(err, data) {
  if(err) { console.trace(e); }
  else {}
});

// You can also read a file by Buffer or Base64 string
var fs = require("fs");
var buffer = fs.readFileSync("/path/to/file.txt");
var base64 = buffer.toString('base64');

r2x.readBuffer(buffer);
r2x.readBase64(base64);

Copy to another place

var metadata = r2x.getMeta();
var copy = new Raid2X(metadata);
var shardCount = metadata.shardList.length;

var shard;
while(shard = r2x.nextShard()) {
  var progress = copy.importShard(shard);
  console.log(progress * 100 + "%");
  
  if(progress == 1) { break; }
}

If the file is divided into 2N shards, you can recovery a it by only N+1 shards

var recovery = new Raid2X(metadata);
for(var i = 0; i < metadata.shardList.length; i++) {
  if(i % 2 == 0 || i == r2x.attr.sliceCount) {
    recovery.importShard(r2x.getShard(i));
  }
}

var N = metadata.shardList.length / 2 + 1;
if(recovery.toBase64() == r2x.toBase64()) { console.log("recovery file with %d shards", N); }
else { console.log("recovery failed :("); }

Get a shard / Import a shard

var sample = new Raid2X(metadata);
var n = 0;

var type = "buffer";
var bufferShard = r2x.getShard(n, type);
sample.importBuffer(bufferShard);

type = "base64";
var base64Shard = r2x.getShard(n, type);
sample.importBase64(base64Shard);
  • n - [INT] the order of the shard
  • type - {buffer|base64} format of the shard

Export the file / Save the file

var bufferFile = r2x.toBinary();
var base64File = r2x.toBase64();

var writeStream = fs.createWriteStream('myBinaryFile');
writeStream.write(bufferFile);
writeStream.end();

Usage in the Web

  • upload somefile
var r2x = new Raid2X();
r2x.readFile(file, function() {
  r2x.uploadAll(path, function(d) {
    console.log(d);
    if(d == 1) {
      console.log("upload complete");
    }
  });
});
  • download somefile
var r2x = new Raid2X(meta);
r2x.downloadAll(path, function(d) {
  console.log(d);
  if(d == 1) {
    // save to local
    r2x.save();
  }
});