New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

file-chunkify

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-chunkify

File Chunkify

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
0
Created
Source

file-chunkify

A lightweight file chunking utility for splitting and merging large files across different environments.

Features

  • Efficiently splits large files into smaller chunks.
  • Supports progressive chunk uploading.
  • Merges chunks back into a single file upon completion.
  • Compatible with various runtime environments.

Installation

Install via npm:

npm install file-chunkify

Usage

File Splitting

Use splitFile to break a large file into chunks before processing:

import { splitFile } from "file-chunkify";

const fileInput = document.querySelector("input[type='file']");
fileInput.addEventListener("change", async (event) => {
  const file = event.target.files[0];
  for await (const chunkInfo of splitFile({
    file,
    chunkSize: 5 * 1024 * 1024,
  })) {
    console.log("Processing chunk", chunkInfo);
    // Send chunkInfo.chunk to the storage or processing pipeline
  }
});

Chunk Storage & Merging

Use saveChunk to store received chunks and merge them when all are received:

import { saveChunk } from "file-chunkify";
import express from "express";
import multer from "multer";

const app = express();
const upload = multer();

app.post("/upload", upload.single("chunk"), async (req, res) => {
  const { chunkNumber, totalChunks } = req.body;
  const result = await saveChunk({
    file: req.file,
    chunkNumber: Number(chunkNumber),
    totalChunks: Number(totalChunks),
    options: { debugMode: true }, // Example usage of debugger
  });
  res.json(result);
});

app.listen(3000, () => console.log("Server running on port 3000"));

API Reference

splitFile(options)

Splits a file into chunks.

Parameters:

NameTypeDefaultDescription
fileFileRequiredThe file to be split.
chunkSizenumber5MBThe size of each chunk.
optionsobjectOptionalAdditional options, including debugMode.

Returns:

An async generator yielding objects with:

  • chunk: A file slice (File)
  • chunkNumber: The current chunk number
  • totalChunks: Total number of chunks
  • fileName: A generated UUID-based file name
  • progress: Split progress in %

saveChunk(options)

Saves uploaded chunks and merges them when all are received.

Parameters:

NameTypeDefaultDescription
fileExpress.Multer.FileRequiredThe uploaded chunk file.
chunkNumbernumberRequiredThe current chunk number.
totalChunksnumberRequiredThe total number of chunks.
outputDirstring./uploadsDirectory to store merged files.
chunkDirstring./uploads/chunksDirectory to store chunk files.
optionsobjectOptionalAdditional options, including debugMode.

Returns:

NameTypeDescription
successbooleanIndicates if the operation was successful.
messagestringA status message.
mergedFilePathstring?The path of the merged file (if applicable).

License

MIT License © 2025 Ahmad Al-Zein

Keywords

file

FAQs

Package last updated on 19 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts