Solution for splitting, checking and merging files.
For TypeScript / JavaScript environment:
npm i @filego/ts
For Node environment:
npm i @filego/node
Usage of different functions in @filego/ts
:
Split files into chunks, and the chunks can be used to check and merge later. It will return the fileSize
, totalChunks
and the chunks
.
import { split } from "@filego/ts";
await split({
file: File,
chunkSize: 1 * 1024 * 1024, // 1MB
});
Check file integrity by verifying the chunks
with fileSize
and totalChunks
parameters. It will return the status
and the error
of the check.
import { check } from "@filego/ts";
await check({
chunks: [ /* ... */ ],
fileSize: 123456789,
totalChunks: 10,
});
Merge the chunks by using the chunks
parameters. It will return the blob
and buffer
of the merged file.
import { merge } from "@filego/ts";
await merge({
chunks: [ /* ... */ ],
});
Usage of different functions in @filego/node
:
Split files from a file path to a directory directly. It will only return the fileSize
and the totalChunks
of the file.
import { split } from "@filego/node";
await split({
inFile: "/path/to/file.txt",
outDir: "/path/to/dir",
chunkSize: 1 * 1024 * 1024,
});
Check file integrity by verifying the the chunks specified in the inDir
with fileSize
, totalChunks
parameters. It will return the status
and the error
of the check.
import { check } from "@filego/node";
await check({
inDir: "/path/to/dir",
fileSize: 123456789,
totalChunks: 10,
});
Merge the chunks from a directory to a specified path directly. Therefore, nothing will be returned.
import { merge } from "@filego/node";
await merge({
inDir: "/path/to/dir",
outFile: "/path/to/file.txt",
});
Check out the Web and API examples.
Direcotry | Description | Link |
---|---|---|
Web | Web example in React | web |
Node | Node example in Fastify | node |
This project is MIT licensed, you can find the license file here.