|
| 1 | +# @oomol-lab/sparse-file |
| 2 | + |
| 3 | +[![github license]](https://github.com/oomol-lab/sparse-file-js/blob/main/LICENSE) [![coveralls]](https://coveralls.io/github/oomol-lab/sparse-file-js) [![npm bundle size]](https://www.npmjs.com/package/@oomol-lab/sparse-file) [![github release]](https://github.com/oomol-lab/sparse-file-js/releases/latest) |
| 4 | + |
| 5 | +Create / Resize sparse file |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +* Support Linux / MacOS |
| 10 | +* Default Safe Mode |
| 11 | +* Not Affected By System Cache |
| 12 | +* Get Physical Size(the space that a file takes up on disk) |
| 13 | +* 100% Code Coverage |
| 14 | +* 0 Dependency |
| 15 | + |
| 16 | +## Install |
| 17 | + |
| 18 | +```bash |
| 19 | +# npm |
| 20 | +npm install @oomol-lab/sparse-file |
| 21 | +# yarn |
| 22 | +yarn add @oomol-lab/sparse-file |
| 23 | +# pnpm |
| 24 | +pnpm add @oomol-lab/sparse-file |
| 25 | +``` |
| 26 | + |
| 27 | +## API |
| 28 | + |
| 29 | +### createSparse(filepath: string, size: number, options?: SparseOptions): Promise\<void\> |
| 30 | + |
| 31 | +* `filepath`: string - Sparse file paths to create/resize |
| 32 | +* `size`: number - Sparse file size |
| 33 | +* `options?.safe`: boolean - Safe mode, default: true |
| 34 | +* `options?.mode`: number - File mode, default: 0o644 |
| 35 | + |
| 36 | +In safe mode, an error will occur if the size is less than 0 or greater than `Number.MAX_SAFE_INTEGER`. Additionally, it will be rejected if the passed size is larger than the current file size. |
| 37 | + |
| 38 | +In non-safe mode, a size less than 0 will be reset to 0, and a size greater than `Number.MAX_SAFE_INTEGER` will be reset to `Number.MAX_SAFE_INTEGER`. |
| 39 | + |
| 40 | +### resizeSparse(filepath: string, size: number, options?: SparseOptions): Promise\<void\> |
| 41 | + |
| 42 | +alias to: `createSparse` |
| 43 | + |
| 44 | +### physicalFileSize(filepath: string): Promise\<number\> |
| 45 | + |
| 46 | +* `filepath`: string - File paths |
| 47 | + |
| 48 | +Return the actual occupied size of the file on the physical hard drive. |
| 49 | + |
| 50 | +[github license]: https://img.shields.io/github/license/oomol-lab/sparse-file-js?style=flat-square&color=9cf |
| 51 | +[coveralls]: https://img.shields.io/coverallsCoverage/github/oomol-lab/sparse-file-js?branch=main&style=flat-square&color=9cf |
| 52 | +[npm bundle size]: https://img.shields.io/bundlephobia/minzip/%40oomol-lab/sparse-file?style=flat-square&color=9cf |
| 53 | +[github release]: https://img.shields.io/github/v/release/oomol-lab/sparse-file-js?style=flat-square&color=9cf |
0 commit comments