split-file-stream
Partition your readable streams into multiple files or combine files into one merged readable stream.
You should use this module if:
- You have a readable stream and want to save to multiple files
- Other solutions require you to supply a path as the source.
- This means you'd have to write your readable stream first, before partitioning the data.
- Faster solution as disk writes are slow
- Other solutions require you to supply a path as the source.
- Vice Versa: You want to pipe the merge output as a stream
- Pipe the merge output to the response of a web request
- Pipe encrypted partitioned files merge output to a decryption stream
Installation
npm install --save split-file-stream
Usage
To split a read stream into multiple files:
var splitFileStream = ;let maxFileSize = 1024; // 1024 bytes per filelet outputPath = __dirname + "/outputFiles"; // file path partition's prefix splitFileStream;
To merge a set of files together into one output stream:
var splitFileStream = ;let filePaths = filePaths; // take this filePaths array from the output of the split method splitFileStream;
To merge a set of files to write to disk:
// Note: You can also do this with the mergeFilesToStream method and piping the stream to a fs writeStream.var splitFileStream = ;let filePaths = filePaths; // take this filePaths array from the output of the split methodlet outputPath = __dirname + "/outputFile"; splitFileStream;
Example usage of the mergeFilesToDisk method using the mergeFilesToStream method:
var fs = ;var splitFileStream = ;let filePaths = filePaths; // take this filePaths array from the output of the split methodlet outputPath = __dirname + "/outputFile"; splitFileStream;
To split a read stream with a custom function that determines the file name:
var splitFileStream = ;let maxFileSize = 1024; // 1024 bytes per filelet outputPath = __dirname + "/outputFiles"; // file path partition's prefixvar customSplit = splitFileStream ;
Alternatively, if you'd like a lower level API for splitting a stream, you can use _splitToStream
. This function will split your readable stream into multiple streams. This function is what is used to implement the split function.
var stream = ;var splitFileStream = ;let partitionStreamSize = 1024; // 1024 bytes per partitionconst outStreamCreate = { return stream;}; splitFileStream;