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/AUTHORS.rst +29 -0
- package/COPYING +661 -0
- package/README.md +305 -0
- package/eslint.config.mjs +38 -0
- package/fs-worker.webpack.config.cjs +48 -0
- package/libtmcsplit.webpack.config.cjs +45 -0
- package/package.json +98 -0
- package/tmcsplit +291 -0
- package/webpack.config.cjs +81 -0
package/tmcsplit
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
|
|
5
|
+
// ----------------------------------------------------------------------
|
|
6
|
+
// Copyright © 2024, 2025 Pellegrino Prevete
|
|
7
|
+
//
|
|
8
|
+
// All rights reserved
|
|
9
|
+
// ----------------------------------------------------------------------
|
|
10
|
+
//
|
|
11
|
+
// This program is free software: you can redistribute it and/or modify
|
|
12
|
+
// it under the terms of the GNU Affero General Public License as published by
|
|
13
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
// (at your option) any later version.
|
|
15
|
+
//
|
|
16
|
+
// This program is distributed in the hope that it will be useful,
|
|
17
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
// GNU Affero General Public License for more details.
|
|
20
|
+
//
|
|
21
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
22
|
+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
23
|
+
|
|
24
|
+
const
|
|
25
|
+
_libcrash =
|
|
26
|
+
require(
|
|
27
|
+
'crash-js');
|
|
28
|
+
_cmdline_check =
|
|
29
|
+
_libcrash._cmdline_check;
|
|
30
|
+
_msg_info =
|
|
31
|
+
_libcrash._msg_info;
|
|
32
|
+
_msg_error =
|
|
33
|
+
_libcrash._msg_error;
|
|
34
|
+
const
|
|
35
|
+
_split_module =
|
|
36
|
+
require(
|
|
37
|
+
"./libtmcsplit");
|
|
38
|
+
_tmcsplit =
|
|
39
|
+
_split_module._tmcsplit;
|
|
40
|
+
|
|
41
|
+
function
|
|
42
|
+
_global_variables() {
|
|
43
|
+
app_name =
|
|
44
|
+
"tmcsplit";
|
|
45
|
+
suffix_length =
|
|
46
|
+
"";
|
|
47
|
+
chunks_amount =
|
|
48
|
+
"";
|
|
49
|
+
string_length =
|
|
50
|
+
"";
|
|
51
|
+
size_max =
|
|
52
|
+
"";
|
|
53
|
+
output_prefix =
|
|
54
|
+
"";
|
|
55
|
+
quiet =
|
|
56
|
+
"";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function
|
|
60
|
+
_overrides_set() {
|
|
61
|
+
if ( suffix_length == "" ) {
|
|
62
|
+
suffix_length =
|
|
63
|
+
"base64";
|
|
64
|
+
}
|
|
65
|
+
if ( output_prefix == "" ) {
|
|
66
|
+
output_prefix =
|
|
67
|
+
_input_file + ".";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function
|
|
72
|
+
_config_show() {
|
|
73
|
+
let
|
|
74
|
+
_line,
|
|
75
|
+
_text;
|
|
76
|
+
_text = [
|
|
77
|
+
`${app_name} configuration:`,
|
|
78
|
+
` Runtime environment: ${runtime_environment}`,
|
|
79
|
+
` Suffix length: ${suffix_length}`,
|
|
80
|
+
` Maximum chunk size: ${size_max} bytes`,
|
|
81
|
+
` Amount of chunks: ${chunks_amount}`,
|
|
82
|
+
` In file: ${input_file}`,
|
|
83
|
+
` Out files prefix: ${output_prefix}`,
|
|
84
|
+
];
|
|
85
|
+
for ( _line of _text ) {
|
|
86
|
+
_msg_info(
|
|
87
|
+
_line);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function
|
|
92
|
+
_usage(
|
|
93
|
+
_exit_code) {
|
|
94
|
+
let
|
|
95
|
+
_line,
|
|
96
|
+
_text;
|
|
97
|
+
_text = [
|
|
98
|
+
"Output pieces of FILE to PREFIXaa, PREFIXab, ...",
|
|
99
|
+
"default size is 1000 lines, and default PREFIX is 'x'.",
|
|
100
|
+
"",
|
|
101
|
+
"Usage:",
|
|
102
|
+
"",
|
|
103
|
+
" tmcsplit",
|
|
104
|
+
" <in-file>",
|
|
105
|
+
" <out-txt-prefix>",
|
|
106
|
+
"",
|
|
107
|
+
" arguments:",
|
|
108
|
+
" <in-file> An input file.",
|
|
109
|
+
" <out-file-prefix> Prefix for the output file(s).",
|
|
110
|
+
"",
|
|
111
|
+
" options:",
|
|
112
|
+
"",
|
|
113
|
+
" -a, --suffix-length=N Generate suffixes of length N",
|
|
114
|
+
` Default: '${suffix_length}'`,
|
|
115
|
+
" --additional-suffix=SUFFIX append an additional SUFFIX",
|
|
116
|
+
" to file names",
|
|
117
|
+
" -b, --bytes=SIZE Put SIZE bytes per output file",
|
|
118
|
+
" -C, --line-bytes=SIZE Put at most SIZE bytes of",
|
|
119
|
+
" records per output file.",
|
|
120
|
+
" -d Use numeric suffixes starting",
|
|
121
|
+
" at 0, not alphabetic",
|
|
122
|
+
" --numeric-suffixes[=FROM] Same as -d, but allow setting",
|
|
123
|
+
" the start value.",
|
|
124
|
+
" -l, --lines=NUMBER Put NUMBER lines/records per",
|
|
125
|
+
" output file.",
|
|
126
|
+
" -n, --number=CHUNKS Generate CHUNKS output files;",
|
|
127
|
+
" see explanation below",
|
|
128
|
+
" -t, --separator=SEP Use SEP instead of newline as",
|
|
129
|
+
" the record separator;",
|
|
130
|
+
" '\0' (zero) specifies the",
|
|
131
|
+
" NUL character.",
|
|
132
|
+
"",
|
|
133
|
+
" -h --help This message.",
|
|
134
|
+
" -v --verbose Enable verbose output.",
|
|
135
|
+
"",
|
|
136
|
+
"The SIZE argument is an integer and optional",
|
|
137
|
+
"unit (example: 10K is 10*1024).",
|
|
138
|
+
"Units are K,M,G,T,P,E,Z,Y,R,Q (powers of 1024)",
|
|
139
|
+
"or KB,MB,... (powers of 1000).",
|
|
140
|
+
"Binary prefixes can be used, too: KiB=K, MiB=M, and so on.",
|
|
141
|
+
"",
|
|
142
|
+
"CHUNKS may be:",
|
|
143
|
+
" N split into N files based on size of input",
|
|
144
|
+
" K/N output Kth of N to standard output",
|
|
145
|
+
" l/N split into N files without splitting lines/records",
|
|
146
|
+
" l/K/N output Kth of N to standard output without",
|
|
147
|
+
" splitting lines/records",
|
|
148
|
+
];
|
|
149
|
+
for ( _line of _text ) {
|
|
150
|
+
_msg_info(
|
|
151
|
+
_line);
|
|
152
|
+
}
|
|
153
|
+
process.exit(
|
|
154
|
+
_exit_code);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function
|
|
158
|
+
_cmdline_parse_help(
|
|
159
|
+
_argv) {
|
|
160
|
+
let
|
|
161
|
+
_help_display;
|
|
162
|
+
_help_display =
|
|
163
|
+
_argv[
|
|
164
|
+
"help"] ||
|
|
165
|
+
_argv[
|
|
166
|
+
"h"];
|
|
167
|
+
if ( _help_display ) {
|
|
168
|
+
quiet =
|
|
169
|
+
"n";
|
|
170
|
+
_usage(
|
|
171
|
+
0);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function
|
|
176
|
+
_input_args_check(
|
|
177
|
+
_argv) {
|
|
178
|
+
if ( _argv[
|
|
179
|
+
"_"].length < 1 ) {
|
|
180
|
+
_msg =
|
|
181
|
+
"Input file argument required.";
|
|
182
|
+
_msg_error(
|
|
183
|
+
_msg,
|
|
184
|
+
0);
|
|
185
|
+
_usage(
|
|
186
|
+
1);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function
|
|
191
|
+
_cmdline_parse() {
|
|
192
|
+
let
|
|
193
|
+
_argv,
|
|
194
|
+
_msg;
|
|
195
|
+
_argv =
|
|
196
|
+
_yargv_get();
|
|
197
|
+
quiet =
|
|
198
|
+
"y";
|
|
199
|
+
runtime_environment =
|
|
200
|
+
"node";
|
|
201
|
+
_cmline_parse_help(
|
|
202
|
+
_argv);
|
|
203
|
+
_input_args_check(
|
|
204
|
+
_argv);
|
|
205
|
+
input_file =
|
|
206
|
+
_argv[
|
|
207
|
+
"_"][
|
|
208
|
+
0];
|
|
209
|
+
if ( _argv[
|
|
210
|
+
"_"].length < 2 ) {
|
|
211
|
+
output_prefix =
|
|
212
|
+
input_file + "."
|
|
213
|
+
}
|
|
214
|
+
if ( "a" in _argv ) {
|
|
215
|
+
suffix_length =
|
|
216
|
+
_argv[
|
|
217
|
+
"a"];
|
|
218
|
+
}
|
|
219
|
+
if ( "suffix-length" in _argv ) {
|
|
220
|
+
suffix_length =
|
|
221
|
+
_argv[
|
|
222
|
+
"suffix-length"];
|
|
223
|
+
}
|
|
224
|
+
chunks_amount =
|
|
225
|
+
_argv[
|
|
226
|
+
"chunks-amount"] ||
|
|
227
|
+
_argv[
|
|
228
|
+
"n"];
|
|
229
|
+
chunks_amount =
|
|
230
|
+
_argv[
|
|
231
|
+
"size-max"] ||
|
|
232
|
+
_argv[
|
|
233
|
+
"b"];
|
|
234
|
+
verbose =
|
|
235
|
+
_argv[
|
|
236
|
+
"verbose"] ||
|
|
237
|
+
_argv[
|
|
238
|
+
"v"];
|
|
239
|
+
if ( verbose ) {
|
|
240
|
+
quiet =
|
|
241
|
+
"n";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function
|
|
246
|
+
_url_parse() {
|
|
247
|
+
let
|
|
248
|
+
_argv;
|
|
249
|
+
runtime_environment =
|
|
250
|
+
"browser";
|
|
251
|
+
_argv =
|
|
252
|
+
_argv_url_get();
|
|
253
|
+
input_file =
|
|
254
|
+
_argv_url_get(
|
|
255
|
+
"input_file")[
|
|
256
|
+
0];
|
|
257
|
+
output_prefix =
|
|
258
|
+
_argv_url_get(
|
|
259
|
+
"output_prefix")[
|
|
260
|
+
0];
|
|
261
|
+
chunks_amount =
|
|
262
|
+
_argv_url_get(
|
|
263
|
+
"chunks_amount")[
|
|
264
|
+
0];
|
|
265
|
+
quiet =
|
|
266
|
+
_argv_url_get(
|
|
267
|
+
"quiet");
|
|
268
|
+
if ( quiet.length === 0 ) {
|
|
269
|
+
quiet =
|
|
270
|
+
"n";
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
_global_variables();
|
|
275
|
+
if ( _cmdline_check(
|
|
276
|
+
"tmcsplit") == true ) {
|
|
277
|
+
_cmdline_parse();
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
_url_parse();
|
|
281
|
+
}
|
|
282
|
+
_config_show();
|
|
283
|
+
app_opts = [
|
|
284
|
+
input_file,
|
|
285
|
+
output_prefix,
|
|
286
|
+
chunks_amount,
|
|
287
|
+
size_max
|
|
288
|
+
];
|
|
289
|
+
_tmcsplit.apply(
|
|
290
|
+
null,
|
|
291
|
+
app_opts);
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
`tmcsplit`;
|
|
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
|
+
const
|
|
26
|
+
_yargs_ignore =
|
|
27
|
+
{ resourceRegExp:
|
|
28
|
+
/^yargs$/ };
|
|
29
|
+
const
|
|
30
|
+
_yargs_helpers_ignore = {
|
|
31
|
+
resourceRegExp:
|
|
32
|
+
/^yargs\/helpers$/ };
|
|
33
|
+
const
|
|
34
|
+
_webpack =
|
|
35
|
+
require(
|
|
36
|
+
"webpack");
|
|
37
|
+
const
|
|
38
|
+
_ignore_plugin =
|
|
39
|
+
_webpack.IgnorePlugin;
|
|
40
|
+
const
|
|
41
|
+
_yargs_ignore_plugin =
|
|
42
|
+
new _ignore_plugin(
|
|
43
|
+
_yargs_ignore);
|
|
44
|
+
const
|
|
45
|
+
_yargs_helpers_ignore_plugin =
|
|
46
|
+
new _ignore_plugin(
|
|
47
|
+
_yargs_helpers_ignore);
|
|
48
|
+
module.exports = {
|
|
49
|
+
entry:
|
|
50
|
+
_input_file_path,
|
|
51
|
+
output:
|
|
52
|
+
_output,
|
|
53
|
+
optimization: {
|
|
54
|
+
moduleIds: 'deterministic',
|
|
55
|
+
},
|
|
56
|
+
resolve: {
|
|
57
|
+
alias: {
|
|
58
|
+
"fs":
|
|
59
|
+
_path.resolve(
|
|
60
|
+
__dirname,
|
|
61
|
+
'node_modules/fs/fs'),
|
|
62
|
+
"path":
|
|
63
|
+
_path.resolve(
|
|
64
|
+
__dirname,
|
|
65
|
+
'node_modules/path/mod.js'),
|
|
66
|
+
},
|
|
67
|
+
fallback: {
|
|
68
|
+
"utils":
|
|
69
|
+
false,
|
|
70
|
+
"web-worker":
|
|
71
|
+
false
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
externals:
|
|
75
|
+
{ yargs:
|
|
76
|
+
'yargs' },
|
|
77
|
+
plugins: [
|
|
78
|
+
_yargs_ignore_plugin,
|
|
79
|
+
_yargs_helpers_ignore_plugin
|
|
80
|
+
]
|
|
81
|
+
};
|