tmcsplit 0.0.1

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/README.md ADDED
@@ -0,0 +1,305 @@
1
+ [comment]: <> (SPDX-License-Identifier: AGPL-3.0)
2
+
3
+ [comment]: <> (-------------------------------------------------------------)
4
+ [comment]: <> (Copyright © 2024, 2025)
5
+ [comment]: <> ( Pellegrino Prevete)
6
+ [comment]: <> (All rights reserved)
7
+ [comment]: <> (-------------------------------------------------------------)
8
+ [comment]: <> (This program is free software: you can redistribute)
9
+ [comment]: <> (it and/or modify it under the terms of the GNU Affero)
10
+ [comment]: <> (General Public License as published by the Free)
11
+ [comment]: <> (Software Foundation, either version 3 of the License.)
12
+
13
+ [comment]: <> (This program is distributed in the hope that it will be useful,)
14
+ [comment]: <> (but WITHOUT ANY WARRANTY; without even the implied warranty of)
15
+ [comment]: <> (MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the)
16
+ [comment]: <> (GNU Affero General Public License for more details.)
17
+
18
+ [comment]: <> (You should have received a copy of the GNU Affero General)
19
+ [comment]: <> (Public License along with this program.)
20
+ [comment]: <> (If not, see <https://www.gnu.org/licenses/>.)
21
+
22
+
23
+ # The Martian Company's Split (`tmcsplit`)
24
+
25
+ Split and merge file in multiple parts.
26
+ Splittable with number of parts or maximum bytes per part.
27
+
28
+ It works both in Node.js and in web browsers.
29
+
30
+ ### Installation
31
+
32
+ You can install and save an entry to your `package.json`
33
+ with the following command:
34
+
35
+ ```bash
36
+ npm \
37
+ install \
38
+ --save \
39
+ @themartiancompany/split-file
40
+ ```
41
+
42
+ ### Usage
43
+
44
+ All methods return a `Promise` (`bluebird`)
45
+ which results in some respose if some.
46
+
47
+ #### Splitting file with number of parts
48
+
49
+ ```javascript
50
+ _split_file(
51
+ _input_file,
52
+ _output_dir?) => Promise<string[]>
53
+ ```
54
+
55
+ **Consumes**:
56
+ - `_input_file`:
57
+ Path to the file to split.
58
+ - `_output_dir`:
59
+ Folder for output, defaults to `.` (current folder)
60
+
61
+ **Produces**:
62
+ - `Promise<string[]>`:
63
+ Promise with results in an array of part
64
+ names (full paths) of the splitted files.
65
+
66
+ #### Example
67
+
68
+ ```javascript
69
+ const
70
+ _split_file_module =
71
+ require(
72
+ 'split-file');
73
+ _split_file =
74
+ _split_file_module._split_file;
75
+ const
76
+ _input_file =
77
+ __dirname +
78
+ '/testfile.bin';
79
+ const
80
+ _parts_amount =
81
+ 3;
82
+ const
83
+ _error_callback =
84
+ function (
85
+ _error) {
86
+ const
87
+ _log =
88
+ console.log;
89
+ _log(
90
+ 'Error: ',
91
+ _error);
92
+ };
93
+ _split_file(
94
+ _input_file,
95
+ _parts_amount)
96
+ .then(
97
+ (_output_files) => {
98
+ console.log(
99
+ _output_files);
100
+ })
101
+ .catch(
102
+ _error_callback);
103
+ ```
104
+
105
+ #### Splitting file with maximum bytes per part
106
+
107
+ ```javascript
108
+ _split_file_by_size(
109
+ _input_file,
110
+ _size_max,
111
+ _output_dir?) => Promise<string[]>
112
+ ```
113
+
114
+ **Consumes**:
115
+ - `_input_file`:
116
+ Path to the file to split.
117
+ - `_size_max`:
118
+ Max size of the splitted parts. (bytes)
119
+ - `_output_dir`:
120
+ Folder for output, defaults to `.` (current folder)
121
+
122
+ **Produces**:
123
+ - `Promise<string[]>`:
124
+ Promise with results in an array of part
125
+ names (full paths) of the splitted files.
126
+
127
+ ##### Example
128
+
129
+ ```javascript
130
+ const
131
+ _split_file_module =
132
+ require(
133
+ 'split-file');
134
+ _split_file_by_size =
135
+ _split_file_module._split_file_by_size;
136
+ const
137
+ _input_file =
138
+ __dirname +
139
+ '/testfile.bin';
140
+ _size_max =
141
+ 457000;
142
+ const
143
+ _error_callback =
144
+ function (
145
+ _error) {
146
+ const
147
+ _log =
148
+ console.log;
149
+ _log(
150
+ 'Error: ',
151
+ _error);
152
+ };
153
+ _split_file_by_size(
154
+ _input_file,
155
+ _size_max)
156
+ .then(
157
+ (_output_files) => {
158
+ console.log(
159
+ _output_files);
160
+ })
161
+ .catch(
162
+ _error_callback);
163
+ ```
164
+
165
+ #### Merge parts
166
+
167
+ ```javascript
168
+ _merge_files(
169
+ _input_files,
170
+ _output_file) => Promise<>
171
+ ```
172
+
173
+ **Consumes**:
174
+ - `_input_files`:
175
+ Input files, array with full part paths.
176
+ - `_output_file`:
177
+ Full path of the output file.
178
+
179
+ **Produces**:
180
+ - `Promise<>`:
181
+ Promise that results in an empty resolving.
182
+
183
+ ##### Example
184
+
185
+ ```javascript
186
+ const
187
+ _split_file_module =
188
+ require(
189
+ 'split-file');
190
+ _merge_files =
191
+ _split_file_module._merge_files;
192
+ const
193
+ _input_files = [
194
+ __dirname + '/file_a',
195
+ __dirname + '/file_b'
196
+ ];
197
+ const
198
+ _output_file =
199
+ __dirname +
200
+ '/testfile-output.bin';
201
+ const
202
+ _error_callback =
203
+ function (
204
+ _error) {
205
+ const
206
+ _log =
207
+ console.log;
208
+ _log(
209
+ 'Error: ',
210
+ _error);
211
+ };
212
+ _merge_files(
213
+ _input_files,
214
+ _output_file)
215
+ .then(
216
+ () => {
217
+ console.log(
218
+ 'Done!');
219
+ })
220
+ .catch(
221
+ _error_callback);
222
+ ```
223
+
224
+ ## Command-line program
225
+
226
+ ### Installation
227
+
228
+ To use the module from the command line you can install
229
+ either use npm and install this package in your global context
230
+
231
+ ```
232
+ npm \
233
+ -g \
234
+ install \
235
+ "split-file"
236
+ ```
237
+
238
+ or just use GNU make
239
+
240
+ ```bash
241
+ make \
242
+ install
243
+ ```
244
+
245
+ **Note:** You may need admin rights (`sudo`,
246
+ `su -c` or on Windows `Run as administrator`).
247
+
248
+ ### Usage
249
+
250
+ The CLI tool works like you use it in your own package.
251
+
252
+ The manual can be accessed with `man split-file`.
253
+
254
+ ```bash
255
+ split-file \
256
+ -h
257
+
258
+ Usage:
259
+
260
+ split-file
261
+ <option>
262
+ [arguments]
263
+
264
+ options:
265
+
266
+ -s Split the input file in
267
+ <input> the given number of parts.
268
+ <num_parts>
269
+
270
+ -x
271
+ <input>
272
+ <max_size> Split the input file into
273
+ multiple parts with maximum
274
+ file size of max_size bytes.
275
+
276
+ -m Merge the given parts into
277
+ <output> the output file.
278
+ <part>
279
+ <part> ...
280
+
281
+ examples:
282
+
283
+ split-file \
284
+ -s \
285
+ "input.bin" \
286
+ 5
287
+
288
+ split-file \
289
+ -x \
290
+ "input.bin" \
291
+ 457000
292
+
293
+ split-file \
294
+ -m \
295
+ "output.bin" \
296
+ "part1" "part2" ...
297
+ ```
298
+
299
+ # License
300
+
301
+ Work authored by Tom Valk is released under the terms
302
+ of the MIT license;
303
+ work authored by Pellegrino Prevete is released
304
+ under the terms of the GNU Affero General Public License
305
+ version 3.
@@ -0,0 +1,38 @@
1
+
2
+ // SPDX-License-Identifier: GPL-3.0-or-later
3
+
4
+ // ----------------------------------------------------------------------
5
+ // Copyright © 2024, 2025
6
+ // Jiang Jie
7
+ // Copyright © 2025
8
+ // Pellegrino Prevete
9
+ //
10
+ // All rights reserved
11
+ // ----------------------------------------------------------------------
12
+ //
13
+ // This program is free software: you can redistribute it and/or modify
14
+ // it under the terms of the GNU General Public License as published by
15
+ // the Free Software Foundation, either version 3 of the License, or
16
+ // (at your option) any later version.
17
+ //
18
+ // This program is distributed in the hope that it will be useful,
19
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ // GNU General Public License for more details.
22
+ //
23
+ // You should have received a copy of the GNU General Public License
24
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
25
+
26
+ import { defineConfig } from "eslint/config";
27
+
28
+ export default defineConfig([
29
+ { ignores: [
30
+ "build/**",
31
+ "eslint.config.js"
32
+ ],
33
+ rules:
34
+ { semi:
35
+ "error",
36
+ "prefer-const":
37
+ "error" } },
38
+ ]);
@@ -0,0 +1,48 @@
1
+ const
2
+ _path =
3
+ require(
4
+ 'path');
5
+ const
6
+ _output_dir =
7
+ _path.resolve(
8
+ __dirname);
9
+ const
10
+ _input_file_name =
11
+ "fs-worker";
12
+ const
13
+ _input_file_path =
14
+ `./node_modules/fs/${_input_file_name}`;
15
+ const
16
+ _output_file_name =
17
+ `${_input_file_name}.js`;
18
+ _output = {
19
+ path:
20
+ _output_dir,
21
+ filename:
22
+ _output_file_name
23
+ };
24
+ module.exports = {
25
+ entry:
26
+ _input_file_path,
27
+ output:
28
+ _output,
29
+ optimization: {
30
+ moduleIds: 'deterministic',
31
+ },
32
+ resolve: {
33
+ alias: {
34
+ "fs":
35
+ _path.resolve(
36
+ __dirname,
37
+ 'node_modules/fs/fs'),
38
+ "opfs":
39
+ _path.resolve(
40
+ __dirname,
41
+ 'node_modules/fs/fs'),
42
+ "path":
43
+ _path.resolve(
44
+ __dirname,
45
+ 'node_modules/path/mod.js'),
46
+ },
47
+ }
48
+ };
@@ -0,0 +1,45 @@
1
+ const
2
+ _path =
3
+ require(
4
+ 'path');
5
+ const
6
+ _output_dir =
7
+ _path.resolve(
8
+ __dirname);
9
+ const
10
+ _input_file_name =
11
+ `libtmcsplit`;
12
+ const
13
+ _input_file_path =
14
+ `./${_input_file_name}`;
15
+ const
16
+ _output_file_name =
17
+ `${_input_file_name}.js`;
18
+ const
19
+ _output = {
20
+ path:
21
+ _output_dir,
22
+ filename:
23
+ _output_file_name
24
+ };
25
+ module.exports = {
26
+ entry:
27
+ _input_file_path,
28
+ output:
29
+ _output,
30
+ optimization: {
31
+ moduleIds: 'deterministic',
32
+ },
33
+ resolve: {
34
+ alias: {
35
+ "fs":
36
+ _path.resolve(
37
+ __dirname,
38
+ 'node_modules/fs/fs'),
39
+ "path":
40
+ _path.resolve(
41
+ __dirname,
42
+ 'node_modules/path/mod.js'),
43
+ },
44
+ },
45
+ };
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+ "name":
3
+ "tmcsplit",
4
+ "version":
5
+ "0.0.1",
6
+ "description":
7
+ "Basic Javascript implementation of GNU Split.",
8
+ "funding": {
9
+ "type":
10
+ "patreon",
11
+ "url":
12
+ "https://patreon.com/tallero"
13
+ },
14
+ "man":
15
+ "./man/tmcsplit.1",
16
+ "files": [
17
+ "AUTHORS.rst",
18
+ "COPYING",
19
+ "README.md",
20
+ "eslint.config.mjs",
21
+ "package.json",
22
+ "tmcsplit.js",
23
+ "tmcsplit",
24
+ "fs-worker.js",
25
+ "fs-worker.webpack.config.cjs",
26
+ "index.html",
27
+ "serve.json",
28
+ "libtmcsplit.webpack.config.cjs",
29
+ "webpack.config.cjs"
30
+ ],
31
+ "keywords": [
32
+ "ur",
33
+ "themartiancompany",
34
+ "dogeos"
35
+ ],
36
+ "homepage":
37
+ "https://github.com/themartiancompany/tmcsplit",
38
+ "bugs": {
39
+ "url":
40
+ "https://github.com/themartiancompany/tmcsplit/issues"
41
+ },
42
+ "repository": {
43
+ "type":
44
+ "git",
45
+ "url":
46
+ "git+https://github.com/themartiancompany/tmcsplit.git"
47
+ },
48
+ "license":
49
+ "AGPL-3.0-or-later",
50
+ "author": {
51
+ "name":
52
+ "Pellegrino Prevete",
53
+ "email":
54
+ "pellegrinoprevete@gmail.com",
55
+ "url":
56
+ "https://github.com/tallero"
57
+ },
58
+ "devDependencies": {
59
+ "crash-js-webpack":
60
+ "^0.0.2",
61
+ "eslint":
62
+ "^9.32.0",
63
+ "serve":
64
+ "^14.2.5",
65
+ "webpack":
66
+ "^5.102.1",
67
+ "webpack-cli":
68
+ "^6.0.1"
69
+ },
70
+ "dependencies": {
71
+ "crash-js":
72
+ "^0.1.66",
73
+ "split-file":
74
+ "npm:@themartiancompany/split-file@2.3.2"
75
+ },
76
+ "type":
77
+ "commonjs",
78
+ "main":
79
+ "tmcsplit",
80
+ "scripts": {
81
+ "build-fs-worker":
82
+ "npx webpack --mode 'production' --config 'fs-worker.webpack.config.cjs' --stats-error-details",
83
+ "build-lib":
84
+ "npx webpack --mode 'production' --config 'libtmcsplit.webpack.config.cjs' --stats-error-details",
85
+ "build-bin":
86
+ "npx webpack --mode 'production' --config 'webpack.config.cjs' --stats-error-details",
87
+ "build":
88
+ "npm run lint && npm run build-fs-worker && npm run build-lib && npm run build-bin",
89
+ "lint":
90
+ "npx eslint .",
91
+ "publish-pnm":
92
+ "npm run build && npm publish --access public",
93
+ "start":
94
+ "serve -c 'serve.json'",
95
+ "test":
96
+ "echo \"Error: no test specified\" && exit 1"
97
+ }
98
+ }