@guanghechen/filepart 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +75 -2
- package/package.json +14 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- chore: vitest config auto-load aliases and coverage thresholds; style/doc formatting updates
|
|
8
|
+
- Updated dependencies:
|
|
9
|
+
- @guanghechen/invariant@7.0.2
|
|
10
|
+
|
|
3
11
|
All notable changes to this project will be documented in this file. See
|
|
4
12
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
13
|
|
|
14
|
+
## 2.0.1 (2025-02-07)
|
|
15
|
+
|
|
16
|
+
### Improvements
|
|
17
|
+
|
|
18
|
+
- Clean up build configs and standardize package exports
|
|
19
|
+
|
|
20
|
+
### Documentation
|
|
21
|
+
|
|
22
|
+
- Update README.md
|
|
23
|
+
|
|
24
|
+
### Miscellaneous
|
|
25
|
+
|
|
26
|
+
- Add LICENSE file
|
|
27
|
+
- Migrate from lerna to changesets
|
|
28
|
+
|
|
29
|
+
## 2.0.0 (2025-01-15)
|
|
30
|
+
|
|
31
|
+
### Improvements
|
|
32
|
+
|
|
33
|
+
- Upgrade to stable release
|
|
34
|
+
|
|
6
35
|
## 1.0.0-alpha.7 (2024-09-18)
|
|
7
36
|
|
|
8
37
|
- :wrench: chore: upgrade devDependencies and fix configs
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present guanghechen (https://github.com/guanghechen)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -49,7 +49,8 @@
|
|
|
49
49
|
</header>
|
|
50
50
|
<br/>
|
|
51
51
|
|
|
52
|
-
File helper utilities for
|
|
52
|
+
File helper utilities for calculating file part ranges and generating part names. Useful for
|
|
53
|
+
splitting large files into smaller chunks.
|
|
53
54
|
|
|
54
55
|
## Install
|
|
55
56
|
|
|
@@ -67,5 +68,77 @@ File helper utilities for splitting files and merging streams.
|
|
|
67
68
|
|
|
68
69
|
## Usage
|
|
69
70
|
|
|
71
|
+
### Calculate File Parts by Size
|
|
72
|
+
|
|
73
|
+
Split a file into parts of a specific size:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { calcFilePartItemsBySize } from '@guanghechen/filepart'
|
|
77
|
+
|
|
78
|
+
const fileSize = 1000 // bytes
|
|
79
|
+
const partSize = 300 // bytes per part
|
|
80
|
+
|
|
81
|
+
const parts = [...calcFilePartItemsBySize(fileSize, partSize)]
|
|
82
|
+
// Result:
|
|
83
|
+
// [
|
|
84
|
+
// { sid: 1, start: 0, end: 300 },
|
|
85
|
+
// { sid: 2, start: 300, end: 600 },
|
|
86
|
+
// { sid: 3, start: 600, end: 900 },
|
|
87
|
+
// { sid: 4, start: 900, end: 1000 }
|
|
88
|
+
// ]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Calculate File Parts by Count
|
|
92
|
+
|
|
93
|
+
Split a file into a specific number of parts:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { calcFilePartItemsByCount } from '@guanghechen/filepart'
|
|
97
|
+
|
|
98
|
+
const fileSize = 1000 // bytes
|
|
99
|
+
const partCount = 3 // number of parts
|
|
100
|
+
|
|
101
|
+
const parts = [...calcFilePartItemsByCount(fileSize, partCount)]
|
|
102
|
+
// Result:
|
|
103
|
+
// [
|
|
104
|
+
// { sid: 1, start: 0, end: 334 },
|
|
105
|
+
// { sid: 2, start: 334, end: 668 },
|
|
106
|
+
// { sid: 3, start: 668, end: 1000 }
|
|
107
|
+
// ]
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Generate Part Names
|
|
111
|
+
|
|
112
|
+
Generate file part names with padded sequence numbers:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { calcFilePartNames, calcFilePartNamesByCount } from '@guanghechen/filepart'
|
|
116
|
+
|
|
117
|
+
// From existing parts
|
|
118
|
+
const parts = [{ sid: 1 }, { sid: 2 }, { sid: 3 }]
|
|
119
|
+
const names = [...calcFilePartNames(parts, '.part')]
|
|
120
|
+
// Result: ['.part1', '.part2', '.part3']
|
|
121
|
+
|
|
122
|
+
// For 14 parts (with zero-padding)
|
|
123
|
+
const names14 = [...calcFilePartNamesByCount(14, '.part')]
|
|
124
|
+
// Result: ['.part01', '.part02', ... '.part14']
|
|
125
|
+
|
|
126
|
+
// Single part returns empty string (no suffix needed)
|
|
127
|
+
const singlePart = [...calcFilePartNamesByCount(1, '.part')]
|
|
128
|
+
// Result: ['']
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Constants
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { DEFAULT_FILEPART_CODE_PREFIX } from '@guanghechen/filepart'
|
|
135
|
+
|
|
136
|
+
console.log(DEFAULT_FILEPART_CODE_PREFIX) // '.ghc-part'
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Reference
|
|
140
|
+
|
|
141
|
+
- [homepage][homepage]
|
|
142
|
+
|
|
70
143
|
[homepage]:
|
|
71
|
-
https://github.com/guanghechen/sora/tree/@guanghechen/filepart@2.0.0/packages/filepart#readme
|
|
144
|
+
https://github.com/guanghechen/sora/tree/@guanghechen/filepart@2.0.0/packages/filepart#readme
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guanghechen/filepart",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "File helper",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "guanghechen",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/guanghechen/sora/tree/@guanghechen/filepart@
|
|
11
|
+
"url": "https://github.com/guanghechen/sora/tree/@guanghechen/filepart@2.0.0",
|
|
12
12
|
"directory": "packages/filepart"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/filepart@
|
|
14
|
+
"homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/filepart@2.0.0/packages/filepart#readme",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"file helper",
|
|
17
17
|
"split file",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"type": "module",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
+
"types": "./lib/types/index.d.ts",
|
|
23
24
|
"source": "./src/index.ts",
|
|
24
25
|
"import": "./lib/esm/index.mjs",
|
|
25
|
-
"require": "./lib/cjs/index.cjs"
|
|
26
|
-
"types": "./lib/types/index.d.ts"
|
|
26
|
+
"require": "./lib/cjs/index.cjs"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"source": "./src/index.ts",
|
|
@@ -31,13 +31,6 @@
|
|
|
31
31
|
"module": "./lib/esm/index.mjs",
|
|
32
32
|
"types": "./lib/types/index.d.ts",
|
|
33
33
|
"license": "MIT",
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "rollup -c ../../rollup.config.mjs",
|
|
36
|
-
"clean": "rimraf lib",
|
|
37
|
-
"test": "vitest run --config ../../vitest.config.ts",
|
|
38
|
-
"test:coverage": "vitest run --config ../../vitest.config.ts --coverage",
|
|
39
|
-
"test:update": "vitest run --config ../../vitest.config.ts -u"
|
|
40
|
-
},
|
|
41
34
|
"files": [
|
|
42
35
|
"lib/",
|
|
43
36
|
"!lib/**/*.map",
|
|
@@ -47,7 +40,13 @@
|
|
|
47
40
|
"README.md"
|
|
48
41
|
],
|
|
49
42
|
"dependencies": {
|
|
50
|
-
"@guanghechen/invariant": "^7.0.
|
|
43
|
+
"@guanghechen/invariant": "^7.0.2"
|
|
51
44
|
},
|
|
52
|
-
"
|
|
53
|
-
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "rollup -c ../../rollup.config.mjs",
|
|
47
|
+
"clean": "rimraf lib",
|
|
48
|
+
"test": "vitest run --config ../../vitest.config.ts",
|
|
49
|
+
"test:coverage": "vitest run --config ../../vitest.config.ts --coverage",
|
|
50
|
+
"test:update": "vitest run --config ../../vitest.config.ts -u"
|
|
51
|
+
}
|
|
52
|
+
}
|