# split-file

> Splitting and merging files with NodeJS

Latest version **2.3.1** (published 2025-12-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install split-file
pnpm add split-file
yarn add split-file
bun add split-file
```

Provides the command `split-file`.

## Health

**Score 53/100 (C)** — status: stable.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.3.1 |
| Published | 2025-12-02 |
| First published | 2015-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/split-file) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45 |
| Author | Tom Valk |
| Maintainers | tomvlk |
| Keywords | split, file, stream |

## Links

- npm: https://www.npmjs.com/package/split-file
- Repository: https://github.com/tomvlk/node-split-file
- Homepage: https://github.com/tomvlk/node-split-file#readme
- Issues: https://github.com/tomvlk/node-split-file/issues
- npm.io page: https://npm.io/package/split-file

## Dependencies (1)

- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 2.3.1 (latest) — 2025-12-02
- 2.3.0 — 2021-09-21
- 2.2.2 — 2021-05-20
- 2.2.1 — 2020-04-07
- 2.2.0 — 2019-11-29
- 2.1.2 — 2019-10-02
- 2.1.1 — 2019-02-28
- 2.1.0 — 2017-05-02
- 2.0.0 — 2017-04-12
- 2.0.0-rc.1 — 2017-03-23
- 2.0.0-beta.1 — 2017-03-02
- 2.0.0-alpha.1 — 2017-02-27
- 1.3.0 — 2017-02-27
- 1.2.0 — 2016-10-19
- 1.1.0 — 2016-07-13
- … 1 more at https://npm.io/package/split-file/versions

## README

# Split File
[![Build Status](https://travis-ci.org/tomvlk/node-split-file.svg?branch=master)](https://travis-ci.org/tomvlk/node-split-file)

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:
```javascript
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:
```javascript
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:
```javascript
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

---
_Source: https://npm.io/package/split-file · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
