Giter Site home page Giter Site logo

tomvlk / node-split-file Goto Github PK

View Code? Open in Web Editor NEW
39.0 3.0 12.0 934 KB

:seedling: NodeJS Module to split and merge files for several purposes like transporting over unstable networks.

License: MIT License

JavaScript 100.00%
split bytes files nodejs npm-package promise

node-split-file's Introduction

Split File

Build Status

Split and merge file in multiple parts. Splittable with number of parts or maximum bytes per part

Programmatically usage

This section contains information on how to use the split-file module in your code.

Installation

You can install and save an entry to your package.json with the following command:

npm i --save split-file

Usage

All methods return a Promise (bluebird) which results in some respose if some.

Splitting file with number of parts

splitFile(file, dest?) => Promise<string[]>

Consumes:

  • file: Path to the file to split.
  • dest: Folder for output, defaults to . (current folder)

Produces:

  • Promise<string[]>: Promise with results in an array of part names (full paths) of the splitted files.

Example:

const splitFile = require('split-file');

splitFile.splitFile(__dirname + '/testfile.bin', 3)
  .then((names) => {
    console.log(names);
  })
  .catch((err) => {
    console.log('Error: ', err);
  });

Splitting file with maximum bytes per part

splitFileBySize(file, maxSize, dest?) => Promise<string[]>

Consumes:

  • file: Path to the file to split.
  • maxSize: Max size of the splitted parts. (bytes)
  • dest: Folder for output, defaults to . (current folder)

Produces:

  • Promise<string[]>: Promise with results in an array of part names (full paths) of the splitted files.

Example:

const splitFile = require('split-file');

splitFile.splitFileBySize(__dirname + '/testfile.bin', 457000)
  .then((names) => {
    console.log(names);
  })
  .catch((err) => {
    console.log('Error: ', err);
  });

Merge parts

mergeFiles(names, outputFile) => Promise<>

Consumes:

  • names: Input files, array with full part paths.
  • outputFile: Full path of the output file.

Produces:

  • Promise<>: Promise that results in an empty resolving.

Example:

const splitFile = require('split-file');

splitFile.mergeFiles(names, __dirname + '/testfile-output.bin')
  .then(() => {
    console.log('Done!');
  })
  .catch((err) => {
    console.log('Error: ', err);
  });

CLI Tool

Installation

To use the module from the commandline you can install this package in your global context:

npm i -g split-file

Some situations you need admin rights (sudo or windows run as admin)

Usage

The CLI tool works like you use it in your own package.

Usage: split-file -s input.bin 5
       split-file -x input.bin 457000
       split-file -m output.bin part1 part2 ...

 -s <input> <num_parts>
    Split the input file in the number of parts given.

 -x <input> <max_size>
    Split the input file into multiple parts with file size maximum of max_size bytes

 -m <output> <part> <part> ...
    Merge the given parts into the output file.

License

License is MIT, see LICENSE

node-split-file's People

Contributors

aleksmeshkov avatar greenkeeper[bot] avatar greenkeeperio-bot avatar lzzy12 avatar netspud avatar purplecones avatar tomvlk avatar total70 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-split-file's Issues

function splitFileBySize problem

This functions not will work correctly
please changing a variable like this

var allparts = parts+1; for (var i = 0; i < allparts; i ++) { partInfo[i] = { number: i + 1, start: i * splitSize, end: (i * splitSize) + splitSize }; if (i === (allparts - 1)) { partInfo[i].end = (i * splitSize) + lastSplitSize; } }
thank you

.splitFileBySize() not working

ReferenceError: parts is not defined
In module there is a line which I think is the problem

SplitFile.prototype.splitFileBySize = function(file, maxSize) {
    var self = this;
    
    // Validate parameters.
    if (parts < 1) {
        return Promise.reject(new Error("Parameter 'parts' is invalid, must contain an integer value."));
    }

parts is not defined because it does not receive any parameter parts just file and maxSize.

splitFile throws an error: expecting a function but got [object Undefined]

I've followed the example here and done this:
in HTML I have:
<input type='file' id='input' @change="testUpload">

const file = document.getElementById('input').files[0];

splitFile.splitFile(file, 3)
  .then((names) => {
    console.log(names);
  })
  .catch((err) => {
    console.log('Error: ', err);
  });

and i get this error:

vue.runtime.esm.js?2b0e:1888 TypeError: expecting a function but got [object Undefined]
    at Function.Promise.promisify (bluebird.js?f684:4098)
    at SplitFile.splitFile (split-file.js?c48c:33)
    at VueComponent.testUpload (SaveData.vue?ad64:103)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
    at HTMLInputElement.invoker (vue.runtime.esm.js?2b0e:2179)
    at HTMLInputElement.original._wrapper (vue.runtime.esm.js?2b0e:6917)

what does this error mean?

TypeError: self.__splitFile is not a function

const { splitFile } = require('split-file')

const uploadFile = (file) => {
    return new Promise((resolve, reject) => {
        splitFile(file.path, 2)
        .then((filePiecesPaths) => {
            console.log(filePiecesPaths)
        })
        .catch((error) => {
            console.error(error);
            reject('Could not split file')
        })
    })
}

Splitting XLXS filetype

When trying to split CheckDetails.xlxs file then generating a file like CheckDetails.xlxs.sf-part01 and so on and when trying to rewrite new xlxs file from the generated file then not able to get back the original file, in fact, getting empty xlsx file

An in-range update of bluebird is breaking the build 🚨

Version 3.5.2 of bluebird was just published.

Branch Build failing 🚨
Dependency bluebird
Current Version 3.5.1
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

bluebird is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes v3.5.2

Bugfixes:

  • Fix PromiseRejectionEvent to contain .reason and .promise properties. (#1509, #1464)
  • Fix promise chain retaining memory until the entire chain is resolved (#1544, #1529)

id: changelog
title: Changelog

Commits

The new version differs by 22 commits.

  • 50067ec Release v3.5.2
  • f290da0 Fix memory being retained until promise queue is completely empty (#1544)
  • ad6d763 Update benchmarks (#1539)
  • 49da1ac Fix a typo. (#1534)
  • b06106a Fix typo in readme introduced in #1530 (#1531)
  • c1dc5b9 Update README.md (#1530)
  • e35455f chore: clone last 5 commits (#1521)
  • 91ae9ce chore: add Node.js 10 (#1523)
  • 9159472 Added a simple usage example (#1369)
  • 39081ba Update promise.each.md (#1479)
  • 77781fe Fix header (#1513)
  • b8eedc1 Update LICENSE to 2018 (#1490)
  • 4163e82 Added ES6 way to import the bluebird promise (#1461)
  • 3790a92 DOC: add direct link to Promise.delay from API ref (#1465)
  • e8d8525 Update error documentation (#1469)

There are 22 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of bluebird is breaking the build 🚨

The dependency bluebird was updated from 3.5.3 to 3.5.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

bluebird is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v3.5.4
  • Proper version check supporting VSCode(#1576)
Commits

The new version differs by 6 commits.

  • e0222e3 Release v3.5.4
  • 4b9fa33 missing --expose-gc flag (#1586)
  • 63b15da docs: improve and compare Promise.each and Promise.mapSeries (#1565)
  • 9dcefe2 .md syntax fix for coming-from-other-languages.md (#1584)
  • b97c0d2 added proper version check supporting VSCode (#1576)
  • 499cf8e Update jsdelivr url in docs (#1571)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Convert to promises

I think it would be nice to provide the 2.x versions with promises (callback + promise or promise only?). This will not only improve the compatibility with ES2015 styles, but also the integrations for the upcoming async await syntax.

@purplecones How is your opinion about this, and related to your projects environment/integrations.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of jest is breaking the build 🚨

Version 22.1.2 of jest was just published.

Branch Build failing 🚨
Dependency jest
Current Version 22.1.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Truncated binary file

I am separating and joining arbitrary binary files. The merged file has a different size from the original and is truncated.

split by size does not work

Split by size (say at 1000000 bytes)

using this:

async function splitFile( filename, chunkSize ) {
  return new Promise(( resolve, reject ) => {
    split.splitFileBySize( __dirname + filename, chunkSize )
      .then(names => {
        resolve( names )
      })
      .catch(err => {
        console.log("NEEEEEEEERRRRRR : ", err);
        reject( err );
      })
  })
} // end splitFile

does this

-rw-r--r--  1  staff   5.0M Oct  2  2017 abc123.mp4
-rw-r--r--  1  staff   977K Oct 25 11:35 abc123.mp4.sf-part1
-rw-r--r--  1  staff   4.0M Oct 25 11:35 abc123.mp4.sf-part2
-rw-r--r--  1  staff   3.1M Oct 25 11:35 abc123.mp4.sf-part3
-rw-r--r--  1  staff   2.1M Oct 25 11:35 abc123.mp4.sf-part4
-rw-r--r--  1  staff   1.2M Oct 25 11:35 abc123.mp4.sf-part5
-rw-r--r--  1  staff   232K Oct 25 11:35 abc123.mp4.sf-part6

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.