Raid2X
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 = ;var filepath = "/Users/luphia/Documents/Workspace/Playground/logo.png";var distination = "/Users/luphia/Desktop/";var r2x = filepath r2x1 meta;r2x;meta = r2x;r2x1 = meta;forvar i = 0; i < metasliceCount; i++ r2x1;r2x1;
Initial Raid2X
var Raid2X = ;var r2x = 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; // You can also read a file by Buffer or Base64 stringvar fs = ;var buffer = fs;var base64 = buffer; r2x;r2x;
Copy to another place
var metadata = r2x;var copy = metadata;var shardCount = metadatashardListlength; var shard;whileshard = r2x var progress = copy; console; ifprogress == 1 break;
If the file is divided into 2N shards, you can recovery a it by only N+1 shards
var recovery = metadata;forvar i = 0; i < metadatashardListlength; i++ ifi % 2 == 0 || i == r2xattrsliceCount recovery; var N = metadatashardListlength / 2 + 1;ifrecovery == r2x console; else console;
Get a shard / Import a shard
var sample = metadata;var n = 0; var type = "buffer";var bufferShard = r2x;sample; type = "base64";var base64Shard = r2x;sample;
- n - [INT] the order of the shard
- type - {buffer|base64} format of the shard
Export the file / Save the file
var bufferFile = r2x;var base64File = r2x; var writeStream = fs;writeStream;writeStream;
Usage in the Web
- upload somefile
var r2x = ;r2x;
- download somefile
var r2x = meta;r2x;