# @guanghechen/file-helper

> File helper

Latest version **1.9.8** (published 2022-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @guanghechen/file-helper
pnpm add @guanghechen/file-helper
yarn add @guanghechen/file-helper
bun add @guanghechen/file-helper
```

## Health

**Score 35/100 (D)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.9.8 |
| Published | 2022-07-27 |
| First published | 2021-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 14.15.0 |
| Dependencies | 2 |
| Unpacked size | 20.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | guanghechen |
| Maintainers | lemonclown |
| Keywords | file helper, split file, merge streams |

## Links

- npm: https://www.npmjs.com/package/@guanghechen/file-helper
- Repository: https://github.com/guanghechen/node-scaffolds
- Homepage: https://github.com/guanghechen/node-scaffolds/tree/main/packages/file-helper#readme
- Issues: https://github.com/guanghechen/node-scaffolds/issues
- npm.io page: https://npm.io/package/@guanghechen/file-helper

## Dependencies (2)

- [fs-extra](https://npm.io/package/fs-extra.md) ^10.1.0
- [@guanghechen/invariant](https://npm.io/package/@guanghechen/invariant.md) ^1.9.8

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.9.8 (latest) — 2022-07-27
- 1.9.7 — 2022-07-17
- 1.9.6 — 2022-07-10
- 1.9.5 — 2022-06-03
- 1.9.4 — 2022-04-27
- 1.9.3 — 2022-04-10
- 1.9.2 — 2022-03-12
- 1.9.1 — 2022-02-23
- 1.9.0 — 2022-02-17
- 1.9.0-alpha.0 — 2022-02-16
- 1.8.6 — 2022-01-15
- 1.8.5 — 2021-12-05
- 1.8.4 — 2021-10-28
- 1.8.3 — 2021-08-18
- 1.8.2 — 2021-08-14
- … 8 more at https://npm.io/package/@guanghechen/file-helper/versions

## README

<header>
  <h1 align="center">
    <a href="https://github.com/guanghechen/node-scaffolds/tree/main/packages/file-helper#readme">@guanghechen/file-helper</a>
  </h1>
  <div align="center">
    <a href="https://www.npmjs.com/package/@guanghechen/file-helper">
      <img
        alt="Npm Version"
        src="https://img.shields.io/npm/v/@guanghechen/file-helper.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@guanghechen/file-helper">
      <img
        alt="Npm Download"
        src="https://img.shields.io/npm/dm/@guanghechen/file-helper.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@guanghechen/file-helper">
      <img
        alt="Npm License"
        src="https://img.shields.io/npm/l/@guanghechen/file-helper.svg"
      />
    </a>
    <a href="#install">
      <img
        alt="Module Formats: cjs"
        src="https://img.shields.io/badge/module_formats-cjs-green.svg"
      />
    </a>
    <a href="https://github.com/nodejs/node">
      <img
        alt="Node.js Version"
        src="https://img.shields.io/node/v/@guanghechen/file-helper"
      />
    </a>
    <a href="https://github.com/facebook/jest">
      <img
        alt="Tested with Jest"
        src="https://img.shields.io/badge/tested_with-jest-9c465e.svg"
      />
    </a>
    <a href="https://github.com/prettier/prettier">
      <img
        alt="Code Style: prettier"
        src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square"
      />
    </a>
  </div>
</header>
<br/>

A collection of utility functions for handling files, such as split big file or
merge multiple small files.


## Install

* npm

  ```bash
  npm install --save @guanghechen/file-helper
  ```

* yarn

  ```bash
  yarn add @guanghechen/file-helper
  ```

## Usage

* `BigFileHelper` (inspired by [split-file][])

  ```typescript
  import { 
    bigFileHelper, 
    calcFilePartItemsBySize,
  } from '@guanghechen/file-helper'

  async function splitFile(filepath: string): Promise<string[]> {
    const parts = calcFilePartItemsBySize(filepath, 1024 * 1024 * 80) // 80MB per chunk 
    const partFilepaths: string[] = await bigFileHelper.split(filepath, parts)
    return partFilepaths
  }

  splitFile('big-file.txt')
  ```

### Overview

Name                                | Description
:----------------------------------:|:----------------------------:
`absoluteOfWorkspace`               | Calc absolute path of p under the workspace
`BigFileHelper`                     | A utility class for split / merging big files
`bigFileHelper`                     | Default instance of `BigFleHelper`
`calcFilePartItemsBySize`           | Generate file part items by part size
`calcFilePartItemsByCount`          | Generate file part items by total of parts
`collectAllFiles`                   | Collect all files under the given directory
`collectAllFilesSync`               | Collect all files under the given directory (synchronizing)
`consumeStreams`                    | Consume multiple streams serially
`ensureCriticalFilepathExistsSync`  | Ensure critical filepath exists
`isDirectorySync`                   | Check whether if the dirpath is a directory path
`isFileSync`                        | Check whether if the filepath is a file path
`isNonExistentOrEmpty`              | Check whether if the dirPath is a non-existent path or empty folder
`mkdirsIfNotExists`                 | Create a path of directories
`relativeOfWorkspace`               | Calc relative path to workspace


[homepage]: https://github.com/guanghechen/node-scaffolds/tree/main/packages/file-helper#readme
[split-file]: https://github.com/tomvlk/node-split-file

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