encoding-tools 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/bin2txt +254 -0
- package/encoding-tools +38 -0
- package/fs-worker.webpack.config.js +45 -0
- package/index.html +24 -0
- package/libbin2txt +122 -0
- package/libtxt2bin +105 -0
- package/package.json +93 -0
- package/serve.json +14 -0
- package/txt2bin +237 -0
- package/webpack.config.js +82 -0
package/bin2txt
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
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
|
+
_encoding_tools =
|
|
36
|
+
require(
|
|
37
|
+
"./encoding-tools");
|
|
38
|
+
_bin2txt =
|
|
39
|
+
_encoding_tools._bin2txt;
|
|
40
|
+
|
|
41
|
+
function
|
|
42
|
+
_global_variables() {
|
|
43
|
+
app_name =
|
|
44
|
+
"bin2txt";
|
|
45
|
+
encoding_format =
|
|
46
|
+
"";
|
|
47
|
+
buffer_size =
|
|
48
|
+
"";
|
|
49
|
+
string_length =
|
|
50
|
+
"";
|
|
51
|
+
in_file =
|
|
52
|
+
"";
|
|
53
|
+
out_txt_prefix =
|
|
54
|
+
"";
|
|
55
|
+
quiet =
|
|
56
|
+
"";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function
|
|
60
|
+
_overrides_set() {
|
|
61
|
+
if ( target_message == "" ) {
|
|
62
|
+
encoding_format =
|
|
63
|
+
"base64";
|
|
64
|
+
}
|
|
65
|
+
if ( string_length == "" ) {
|
|
66
|
+
string_length =
|
|
67
|
+
"10000";
|
|
68
|
+
}
|
|
69
|
+
if ( buffer_size == "" ) {
|
|
70
|
+
buffer_size =
|
|
71
|
+
"2000000"; // 2MB
|
|
72
|
+
}
|
|
73
|
+
if ( amount_only == false ) {
|
|
74
|
+
amount_only =
|
|
75
|
+
false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function
|
|
80
|
+
_config_show() {
|
|
81
|
+
let
|
|
82
|
+
_line,
|
|
83
|
+
_text;
|
|
84
|
+
_text = [
|
|
85
|
+
`${app_name} configuration:`,
|
|
86
|
+
` Runtime environment: ${runtime_environment}`,
|
|
87
|
+
` Encoding format: ${encoding_format}`,
|
|
88
|
+
` Buffer size: ${buffer_size}`,
|
|
89
|
+
` Chunk string length: ${string_length}`,
|
|
90
|
+
` Chunks amount only: ${amount_only}`,
|
|
91
|
+
` In file: ${in_file}`,
|
|
92
|
+
` Out text prefix: ${out_txt_prefix}`,
|
|
93
|
+
];
|
|
94
|
+
for ( _line of _text ) {
|
|
95
|
+
_msg_info(
|
|
96
|
+
_line);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function
|
|
101
|
+
_usage(
|
|
102
|
+
_exit_code) {
|
|
103
|
+
let
|
|
104
|
+
_line,
|
|
105
|
+
_text;
|
|
106
|
+
_text = [
|
|
107
|
+
"Converts binary to ascii text.",
|
|
108
|
+
"",
|
|
109
|
+
"Usage:",
|
|
110
|
+
"",
|
|
111
|
+
" bin2txt",
|
|
112
|
+
" <in-file>",
|
|
113
|
+
" <out-txt-prefix>",
|
|
114
|
+
"",
|
|
115
|
+
" arguments:",
|
|
116
|
+
" <in-file> An input file.",
|
|
117
|
+
" <out-file-prefix> Prefix for the output file(s).",
|
|
118
|
+
"",
|
|
119
|
+
" options:",
|
|
120
|
+
"",
|
|
121
|
+
" -f --encoding-format Encoding format ('base64').",
|
|
122
|
+
` <encoding-format> Default: '${encoding_format}`,
|
|
123
|
+
"",
|
|
124
|
+
" -B --buffer-size Size in bytes the input file will",
|
|
125
|
+
" <buffer-size> be split before being read",
|
|
126
|
+
" in memory and passed to",
|
|
127
|
+
" the encoder.",
|
|
128
|
+
` Default: '${buffer_size}'`,
|
|
129
|
+
"",
|
|
130
|
+
" -L --string-length String chunk length.",
|
|
131
|
+
` <string-length> Default: '${string_length}'`,
|
|
132
|
+
"",
|
|
133
|
+
" -s --amount-only Only print chunks amount.",
|
|
134
|
+
` Default: '${amount_only}'`,
|
|
135
|
+
"",
|
|
136
|
+
" -h --help This message.",
|
|
137
|
+
" -v --verbose Enable verbose output."
|
|
138
|
+
];
|
|
139
|
+
for ( _line of _text ) {
|
|
140
|
+
_msg_info(
|
|
141
|
+
_line);
|
|
142
|
+
}
|
|
143
|
+
process.exit(
|
|
144
|
+
_exit_code);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function
|
|
148
|
+
_cmdline_parse() {
|
|
149
|
+
let
|
|
150
|
+
_argv,
|
|
151
|
+
_msg;
|
|
152
|
+
_argv =
|
|
153
|
+
_yargv_get();
|
|
154
|
+
quiet =
|
|
155
|
+
"y";
|
|
156
|
+
runtime_environment =
|
|
157
|
+
"node";
|
|
158
|
+
help_display =
|
|
159
|
+
_argv[
|
|
160
|
+
"help"] ||
|
|
161
|
+
_argv[
|
|
162
|
+
"h"];
|
|
163
|
+
if ( help_display ) {
|
|
164
|
+
quiet =
|
|
165
|
+
"n";
|
|
166
|
+
_usage(
|
|
167
|
+
0);
|
|
168
|
+
}
|
|
169
|
+
if ( _argv[
|
|
170
|
+
"_"].length < 1 ) {
|
|
171
|
+
_msg =
|
|
172
|
+
"Input file argument required.";
|
|
173
|
+
_msg_error(
|
|
174
|
+
_msg,
|
|
175
|
+
0);
|
|
176
|
+
_usage(
|
|
177
|
+
1);
|
|
178
|
+
}
|
|
179
|
+
in_file =
|
|
180
|
+
_argv[
|
|
181
|
+
"_"][
|
|
182
|
+
0];
|
|
183
|
+
if ( _argv[
|
|
184
|
+
"_"].length < 2 ) {
|
|
185
|
+
out_txt_prefix =
|
|
186
|
+
in_file + ".base64"
|
|
187
|
+
}
|
|
188
|
+
if ( "s" in _argv ) {
|
|
189
|
+
string_length =
|
|
190
|
+
_argv[
|
|
191
|
+
"s"];
|
|
192
|
+
}
|
|
193
|
+
if ( "string-length" in _argv ) {
|
|
194
|
+
string_length =
|
|
195
|
+
_argv[
|
|
196
|
+
"string-length"];
|
|
197
|
+
}
|
|
198
|
+
amount_only =
|
|
199
|
+
_argv[
|
|
200
|
+
"amount-only"] ||
|
|
201
|
+
_argv[
|
|
202
|
+
"s"];
|
|
203
|
+
verbose =
|
|
204
|
+
_argv[
|
|
205
|
+
"verbose"] ||
|
|
206
|
+
_argv[
|
|
207
|
+
"v"];
|
|
208
|
+
if ( verbose ) {
|
|
209
|
+
quiet =
|
|
210
|
+
"n";
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function
|
|
215
|
+
_url_parse() {
|
|
216
|
+
let
|
|
217
|
+
_argv;
|
|
218
|
+
runtime_environment =
|
|
219
|
+
"browser";
|
|
220
|
+
_argv =
|
|
221
|
+
_argv_url_get();
|
|
222
|
+
in_file =
|
|
223
|
+
_argv_url_get(
|
|
224
|
+
"in_file")[
|
|
225
|
+
0];
|
|
226
|
+
target_planet =
|
|
227
|
+
_argv_url_get(
|
|
228
|
+
"out_txt_prefix")[
|
|
229
|
+
0];
|
|
230
|
+
quiet =
|
|
231
|
+
_argv_url_get(
|
|
232
|
+
"quiet");
|
|
233
|
+
if ( quiet.length === 0 ) {
|
|
234
|
+
quiet =
|
|
235
|
+
"n";
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
_global_variables();
|
|
240
|
+
if ( _cmdline_check(
|
|
241
|
+
"bin2txt") == true ) {
|
|
242
|
+
_cmdline_parse();
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
_url_parse();
|
|
246
|
+
}
|
|
247
|
+
_config_show();
|
|
248
|
+
app_opts = [
|
|
249
|
+
in_file,
|
|
250
|
+
out_txt_prefix
|
|
251
|
+
];
|
|
252
|
+
_bin2txt.apply(
|
|
253
|
+
null,
|
|
254
|
+
app_opts);
|
package/encoding-tools
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
_bin2txt_module =
|
|
26
|
+
require(
|
|
27
|
+
"./libbin2txt");
|
|
28
|
+
// const
|
|
29
|
+
// _libtxt2bin =
|
|
30
|
+
// require(
|
|
31
|
+
// "./txt2bin");
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
_bin2txt:
|
|
35
|
+
_bin2txt_module._bin2txt
|
|
36
|
+
// _txt2bin:
|
|
37
|
+
// _txt2bin
|
|
38
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
let
|
|
2
|
+
_file_name,
|
|
3
|
+
_output,
|
|
4
|
+
_output_dir,
|
|
5
|
+
_path;
|
|
6
|
+
_path =
|
|
7
|
+
require(
|
|
8
|
+
'path');
|
|
9
|
+
_output_dir =
|
|
10
|
+
_path.resolve(
|
|
11
|
+
__dirname);
|
|
12
|
+
_file_name =
|
|
13
|
+
"fs-worker.js";
|
|
14
|
+
_output = {
|
|
15
|
+
path:
|
|
16
|
+
_output_dir,
|
|
17
|
+
filename:
|
|
18
|
+
_file_name
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
entry:
|
|
23
|
+
'./node_modules/crash-js/crash-js/fs-worker',
|
|
24
|
+
output:
|
|
25
|
+
_output,
|
|
26
|
+
optimization: {
|
|
27
|
+
moduleIds: 'deterministic',
|
|
28
|
+
},
|
|
29
|
+
resolve: {
|
|
30
|
+
fallback: {
|
|
31
|
+
"fs":
|
|
32
|
+
false,
|
|
33
|
+
"happy-opfs":
|
|
34
|
+
_path.resolve(
|
|
35
|
+
__dirname,
|
|
36
|
+
'node_modules/happy-opfs/dist/main.mjs'),
|
|
37
|
+
"path":
|
|
38
|
+
false,
|
|
39
|
+
"@std/path":
|
|
40
|
+
_path.resolve(
|
|
41
|
+
__dirname,
|
|
42
|
+
'node_modules/@std/path/mod.js'),
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
package/index.html
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
|
|
4
|
+
----------------------------------------------------------------------
|
|
5
|
+
Copyright © 2024, 2025 Pellegrino Prevete
|
|
6
|
+
|
|
7
|
+
All rights reserved
|
|
8
|
+
----------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
This program is free software: you can redistribute it and/or modify
|
|
11
|
+
it under the terms of the GNU Affero General Public License as published by
|
|
12
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
13
|
+
(at your option) any later version.
|
|
14
|
+
|
|
15
|
+
This program is distributed in the hope that it will be useful,
|
|
16
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
GNU Affero General Public License for more details.
|
|
19
|
+
|
|
20
|
+
You should have received a copy of the GNU Affero General Public License
|
|
21
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
22
|
+
-->
|
|
23
|
+
|
|
24
|
+
<script src="ahsi.js"></script>
|
package/libbin2txt
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
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
|
|
13
|
+
// published by the Free Software Foundation, either version 3 of
|
|
14
|
+
// the License, or (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
|
+
_error_display =
|
|
29
|
+
_libcrash._error_display;
|
|
30
|
+
_ext_rm =
|
|
31
|
+
_libcrash._ext_rm;
|
|
32
|
+
_file_read =
|
|
33
|
+
_libcrash._file_read;
|
|
34
|
+
_file_write =
|
|
35
|
+
_libcrash._file_write;
|
|
36
|
+
_fs_worker_start =
|
|
37
|
+
_libcrash._fs_worker_start;
|
|
38
|
+
_json_read =
|
|
39
|
+
_libcrash._json_read;
|
|
40
|
+
_ls =
|
|
41
|
+
_libcrash._ls;
|
|
42
|
+
_mkdir =
|
|
43
|
+
_libcrash._mkdir;
|
|
44
|
+
_msg_info =
|
|
45
|
+
_libcrash._msg_info;
|
|
46
|
+
_msg_error =
|
|
47
|
+
_libcrash._msg_error;
|
|
48
|
+
_split =
|
|
49
|
+
_libcrash._split;
|
|
50
|
+
|
|
51
|
+
async function
|
|
52
|
+
_bin2txt(
|
|
53
|
+
_in,
|
|
54
|
+
_out,
|
|
55
|
+
_format,
|
|
56
|
+
_length,
|
|
57
|
+
_buffer_size_bytes,
|
|
58
|
+
_amount_only) {
|
|
59
|
+
let
|
|
60
|
+
_blocks_total,
|
|
61
|
+
_chunks_total,
|
|
62
|
+
_chunk_current,
|
|
63
|
+
_block_current,
|
|
64
|
+
_block_last,
|
|
65
|
+
_dir,
|
|
66
|
+
_file,
|
|
67
|
+
_msg,
|
|
68
|
+
_worker;
|
|
69
|
+
_dir =
|
|
70
|
+
"/test_dir";
|
|
71
|
+
_file =
|
|
72
|
+
`${_dir}/test_file`;
|
|
73
|
+
_content =
|
|
74
|
+
`${_in} ${_out}`;
|
|
75
|
+
if ( typeof window !== 'undefined' ) {
|
|
76
|
+
await _fs_worker_start(
|
|
77
|
+
"fs-worker.js");
|
|
78
|
+
}
|
|
79
|
+
_split(
|
|
80
|
+
"red-sun-in-the-sky.mp4",
|
|
81
|
+
2,
|
|
82
|
+
|
|
83
|
+
console.log(
|
|
84
|
+
_split
|
|
85
|
+
);
|
|
86
|
+
// _msg =
|
|
87
|
+
// `Creating directory '${_dir}':`;
|
|
88
|
+
// _msg_info(
|
|
89
|
+
// _msg);
|
|
90
|
+
// _mkdir(
|
|
91
|
+
// _dir);
|
|
92
|
+
// _msg =
|
|
93
|
+
// `Writing content '${_content}' to file '${_file}':`;
|
|
94
|
+
// _msg_info(
|
|
95
|
+
// _msg);
|
|
96
|
+
// _file_write(
|
|
97
|
+
// _file,
|
|
98
|
+
// _content);
|
|
99
|
+
// _msg =
|
|
100
|
+
// `Content of directory '/':`;
|
|
101
|
+
// _msg_info(
|
|
102
|
+
// _msg);
|
|
103
|
+
// _dir_content =
|
|
104
|
+
// _ls(
|
|
105
|
+
// "/").unwrap();
|
|
106
|
+
// console.log(
|
|
107
|
+
// _dir_content);
|
|
108
|
+
// _msg =
|
|
109
|
+
// `Content of directory '${_dir}':`;
|
|
110
|
+
// _msg_info(
|
|
111
|
+
// _msg);
|
|
112
|
+
// _dir_content =
|
|
113
|
+
// _ls(
|
|
114
|
+
// _dir).unwrap();
|
|
115
|
+
// console.log(
|
|
116
|
+
// _dir_content);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = {
|
|
120
|
+
_bin2txt:
|
|
121
|
+
_bin2txt,
|
|
122
|
+
};
|
package/libtxt2bin
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
_error_display =
|
|
29
|
+
_libcrash._error_display;
|
|
30
|
+
_ext_rm =
|
|
31
|
+
_libcrash._ext_rm;
|
|
32
|
+
_file_read =
|
|
33
|
+
_libcrash._file_read;
|
|
34
|
+
_file_write =
|
|
35
|
+
_libcrash._file_write;
|
|
36
|
+
_fs_worker_start =
|
|
37
|
+
_libcrash._fs_worker_start;
|
|
38
|
+
_json_read =
|
|
39
|
+
_libcrash._json_read;
|
|
40
|
+
_ls =
|
|
41
|
+
_libcrash._ls;
|
|
42
|
+
_mkdir =
|
|
43
|
+
_libcrash._mkdir;
|
|
44
|
+
_msg_info =
|
|
45
|
+
_libcrash._msg_info;
|
|
46
|
+
_msg_error =
|
|
47
|
+
_libcrash._msg_error;
|
|
48
|
+
|
|
49
|
+
async function
|
|
50
|
+
_ahsi(
|
|
51
|
+
_target_message,
|
|
52
|
+
_target_planet) {
|
|
53
|
+
let
|
|
54
|
+
_agent,
|
|
55
|
+
_dir_content,
|
|
56
|
+
_content,
|
|
57
|
+
_dir,
|
|
58
|
+
_file,
|
|
59
|
+
_msg,
|
|
60
|
+
_worker;
|
|
61
|
+
_dir =
|
|
62
|
+
"/test_dir";
|
|
63
|
+
_file =
|
|
64
|
+
`${_dir}/test_file`;
|
|
65
|
+
_content =
|
|
66
|
+
`${_target_message} ${_target_planet}`;
|
|
67
|
+
await _fs_worker_start(
|
|
68
|
+
"fs-worker.js");
|
|
69
|
+
_msg =
|
|
70
|
+
`Creating directory '${_dir}':`;
|
|
71
|
+
_msg_info(
|
|
72
|
+
_msg);
|
|
73
|
+
_mkdir(
|
|
74
|
+
_dir);
|
|
75
|
+
_msg =
|
|
76
|
+
`Writing content '${_content}' to file '${_file}':`;
|
|
77
|
+
_msg_info(
|
|
78
|
+
_msg);
|
|
79
|
+
_file_write(
|
|
80
|
+
_file,
|
|
81
|
+
_content);
|
|
82
|
+
_msg =
|
|
83
|
+
`Content of directory '/':`;
|
|
84
|
+
_msg_info(
|
|
85
|
+
_msg);
|
|
86
|
+
_dir_content =
|
|
87
|
+
_ls(
|
|
88
|
+
"/").unwrap();
|
|
89
|
+
console.log(
|
|
90
|
+
_dir_content);
|
|
91
|
+
_msg =
|
|
92
|
+
`Content of directory '${_dir}':`;
|
|
93
|
+
_msg_info(
|
|
94
|
+
_msg);
|
|
95
|
+
_dir_content =
|
|
96
|
+
_ls(
|
|
97
|
+
_dir).unwrap();
|
|
98
|
+
console.log(
|
|
99
|
+
_dir_content);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = {
|
|
103
|
+
_txt2bin:
|
|
104
|
+
_txt2bin
|
|
105
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name":
|
|
3
|
+
"encoding-tools",
|
|
4
|
+
"version":
|
|
5
|
+
"0.0.1",
|
|
6
|
+
"description":
|
|
7
|
+
"A multi-language collection of encoding tools.",
|
|
8
|
+
"funding": {
|
|
9
|
+
"type":
|
|
10
|
+
"patreon",
|
|
11
|
+
"url":
|
|
12
|
+
"https://patreon.com/tallero"
|
|
13
|
+
},
|
|
14
|
+
"man":
|
|
15
|
+
"./man/ahsi.1",
|
|
16
|
+
"files": [
|
|
17
|
+
"AUTHORS.rst",
|
|
18
|
+
"COPYING",
|
|
19
|
+
"README.md",
|
|
20
|
+
"bin2txt",
|
|
21
|
+
"libbin2txt",
|
|
22
|
+
"libtxt2bin",
|
|
23
|
+
"ahsi",
|
|
24
|
+
"fs-worker.js",
|
|
25
|
+
"fs-worker.webpack.config.js",
|
|
26
|
+
"index.html",
|
|
27
|
+
"package.json",
|
|
28
|
+
"serve.json",
|
|
29
|
+
"txt2bin",
|
|
30
|
+
"webpack.config.js"
|
|
31
|
+
],
|
|
32
|
+
"keywords": [
|
|
33
|
+
"ur",
|
|
34
|
+
"themartiancompany",
|
|
35
|
+
"dogeos"
|
|
36
|
+
],
|
|
37
|
+
"homepage":
|
|
38
|
+
"https://github.com/themartiancompany/encoding-tools",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url":
|
|
41
|
+
"https://github.com/themartiancompany/encoding-tools/issues"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type":
|
|
45
|
+
"git",
|
|
46
|
+
"url":
|
|
47
|
+
"git+https://github.com/themartiancompany/encoding-tools.git"
|
|
48
|
+
},
|
|
49
|
+
"license":
|
|
50
|
+
"AGPL-3.0-or-later",
|
|
51
|
+
"author": {
|
|
52
|
+
"name":
|
|
53
|
+
"Pellegrino Prevete",
|
|
54
|
+
"email":
|
|
55
|
+
"pellegrinoprevete@gmail.com",
|
|
56
|
+
"url":
|
|
57
|
+
"https://github.com/tallero"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"eslint":
|
|
61
|
+
"^9.32.0",
|
|
62
|
+
"safely-serve":
|
|
63
|
+
"^0.0.9",
|
|
64
|
+
"webpack":
|
|
65
|
+
"^5.102.1",
|
|
66
|
+
"webpack-cli":
|
|
67
|
+
"^6.0.1"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"crash-js":
|
|
71
|
+
"^0.1.51",
|
|
72
|
+
"tmcsplit":
|
|
73
|
+
"^0.0.2",
|
|
74
|
+
"yargs":
|
|
75
|
+
"18.0.0"
|
|
76
|
+
},
|
|
77
|
+
"type":
|
|
78
|
+
"commonjs",
|
|
79
|
+
"main":
|
|
80
|
+
"encoding-tools",
|
|
81
|
+
"scripts": {
|
|
82
|
+
"build":
|
|
83
|
+
"cd ../.. && make build-npm && encoding-tools/nodejs",
|
|
84
|
+
"lint":
|
|
85
|
+
"npx eslint .",
|
|
86
|
+
"publish-npm":
|
|
87
|
+
"npm run build && npm publish --access public",
|
|
88
|
+
"start":
|
|
89
|
+
"serve -c 'serve.json'",
|
|
90
|
+
"test":
|
|
91
|
+
"echo \"Error: no test specified\" && exit 1"
|
|
92
|
+
}
|
|
93
|
+
}
|
package/serve.json
ADDED
package/txt2bin
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
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
|
+
_argv_get =
|
|
29
|
+
_libcrash._argv_get;
|
|
30
|
+
_cmdline_check =
|
|
31
|
+
_libcrash._cmdline_check;
|
|
32
|
+
_error_display =
|
|
33
|
+
_libcrash._error_display;
|
|
34
|
+
_ext_rm =
|
|
35
|
+
_libcrash._ext_rm;
|
|
36
|
+
_file_read =
|
|
37
|
+
_libcrash._file_read;
|
|
38
|
+
_file_write =
|
|
39
|
+
_libcrash._file_write;
|
|
40
|
+
_fs_worker_start =
|
|
41
|
+
_libcrash._fs_worker_start;
|
|
42
|
+
_json_read =
|
|
43
|
+
_libcrash._json_read;
|
|
44
|
+
_ls =
|
|
45
|
+
_libcrash._ls;
|
|
46
|
+
_mkdir =
|
|
47
|
+
_libcrash._mkdir;
|
|
48
|
+
_msg_info =
|
|
49
|
+
_libcrash._msg_info;
|
|
50
|
+
_msg_error =
|
|
51
|
+
_libcrash._msg_error;
|
|
52
|
+
|
|
53
|
+
function
|
|
54
|
+
_global_variables() {
|
|
55
|
+
app_name =
|
|
56
|
+
"ahsi";
|
|
57
|
+
target_message =
|
|
58
|
+
"";
|
|
59
|
+
target_planet =
|
|
60
|
+
"";
|
|
61
|
+
runtime_environment =
|
|
62
|
+
"";
|
|
63
|
+
quiet =
|
|
64
|
+
"";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function
|
|
68
|
+
_ahsi(
|
|
69
|
+
_target_message,
|
|
70
|
+
_target_planet) {
|
|
71
|
+
let
|
|
72
|
+
_agent,
|
|
73
|
+
_dir_content,
|
|
74
|
+
_content,
|
|
75
|
+
_dir,
|
|
76
|
+
_file,
|
|
77
|
+
_msg,
|
|
78
|
+
_worker;
|
|
79
|
+
_dir =
|
|
80
|
+
"/test_dir";
|
|
81
|
+
_file =
|
|
82
|
+
`${_dir}/test_file`;
|
|
83
|
+
_content =
|
|
84
|
+
`${_target_message} ${_target_planet}`;
|
|
85
|
+
await _fs_worker_start(
|
|
86
|
+
"fs-worker.js");
|
|
87
|
+
_msg =
|
|
88
|
+
`Creating directory '${_dir}':`;
|
|
89
|
+
_msg_info(
|
|
90
|
+
_msg);
|
|
91
|
+
_mkdir(
|
|
92
|
+
_dir);
|
|
93
|
+
_msg =
|
|
94
|
+
`Writing content '${_content}' to file '${_file}':`;
|
|
95
|
+
_msg_info(
|
|
96
|
+
_msg);
|
|
97
|
+
_file_write(
|
|
98
|
+
_file,
|
|
99
|
+
_content);
|
|
100
|
+
_msg =
|
|
101
|
+
`Content of directory '/':`;
|
|
102
|
+
_msg_info(
|
|
103
|
+
_msg);
|
|
104
|
+
_dir_content =
|
|
105
|
+
_ls(
|
|
106
|
+
"/").unwrap();
|
|
107
|
+
console.log(
|
|
108
|
+
_dir_content);
|
|
109
|
+
_msg =
|
|
110
|
+
`Content of directory '${_dir}':`;
|
|
111
|
+
_msg_info(
|
|
112
|
+
_msg);
|
|
113
|
+
_dir_content =
|
|
114
|
+
_ls(
|
|
115
|
+
_dir).unwrap();
|
|
116
|
+
console.log(
|
|
117
|
+
_dir_content);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function
|
|
121
|
+
_config_show() {
|
|
122
|
+
let
|
|
123
|
+
_line,
|
|
124
|
+
_text;
|
|
125
|
+
_text = [
|
|
126
|
+
` Runtime environment: ${runtime_environment}`,
|
|
127
|
+
` Target message: ${target_message}`,
|
|
128
|
+
` Target planet: ${target_planet}`,
|
|
129
|
+
];
|
|
130
|
+
for ( _line of _text ) {
|
|
131
|
+
_msg_info(
|
|
132
|
+
_line);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
function
|
|
138
|
+
_usage(
|
|
139
|
+
_exit_code) {
|
|
140
|
+
let
|
|
141
|
+
_line,
|
|
142
|
+
_text;
|
|
143
|
+
_text = [
|
|
144
|
+
"Hello world application for browsers and computers",
|
|
145
|
+
"",
|
|
146
|
+
"Usage:",
|
|
147
|
+
" ahsi",
|
|
148
|
+
" <quiet>",
|
|
149
|
+
" <message>",
|
|
150
|
+
" <planet>",
|
|
151
|
+
"",
|
|
152
|
+
"Args:",
|
|
153
|
+
" <quiet> Can be 'y' or 'n'",
|
|
154
|
+
" Default: y",
|
|
155
|
+
];
|
|
156
|
+
for ( _line of _text ) {
|
|
157
|
+
_msg_info(
|
|
158
|
+
_line);
|
|
159
|
+
}
|
|
160
|
+
process.exit(
|
|
161
|
+
_exit_code);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function
|
|
165
|
+
_cmdline_parse() {
|
|
166
|
+
quiet =
|
|
167
|
+
"y";
|
|
168
|
+
runtime_environment =
|
|
169
|
+
"node";
|
|
170
|
+
process.argv.forEach(
|
|
171
|
+
function (
|
|
172
|
+
_value,
|
|
173
|
+
_index,
|
|
174
|
+
_array) {
|
|
175
|
+
if ( _index == 2 ) {
|
|
176
|
+
quiet =
|
|
177
|
+
_value;
|
|
178
|
+
}
|
|
179
|
+
if ( _index == 3 ) {
|
|
180
|
+
target_message =
|
|
181
|
+
_value;
|
|
182
|
+
}
|
|
183
|
+
if ( _index == 4 ) {
|
|
184
|
+
target_planet =
|
|
185
|
+
_value;
|
|
186
|
+
}
|
|
187
|
+
if ( _value == "-h" ||
|
|
188
|
+
_value == "--help" ) {
|
|
189
|
+
quiet =
|
|
190
|
+
"n";
|
|
191
|
+
_usage(
|
|
192
|
+
0);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function
|
|
198
|
+
_url_parse() {
|
|
199
|
+
let
|
|
200
|
+
_argv;
|
|
201
|
+
runtime_environment =
|
|
202
|
+
"browser";
|
|
203
|
+
_argv =
|
|
204
|
+
_argv_url_get();
|
|
205
|
+
target_message =
|
|
206
|
+
_argv_url_get(
|
|
207
|
+
"target_message")[0];
|
|
208
|
+
target_planet =
|
|
209
|
+
_argv_url_get(
|
|
210
|
+
"target_planet")[0];
|
|
211
|
+
quiet =
|
|
212
|
+
_argv_url_get(
|
|
213
|
+
"quiet");
|
|
214
|
+
if ( quiet.length === 0 ) {
|
|
215
|
+
quiet =
|
|
216
|
+
"n";
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
_global_variables();
|
|
221
|
+
|
|
222
|
+
_global_variables();
|
|
223
|
+
if ( _cmdline_check(
|
|
224
|
+
"ahsi") == true ) {
|
|
225
|
+
_cmdline_parse();
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
_url_parse();
|
|
229
|
+
}
|
|
230
|
+
_config_show();
|
|
231
|
+
app_opts = [
|
|
232
|
+
target_message,
|
|
233
|
+
target_planet
|
|
234
|
+
];
|
|
235
|
+
_ahsi.apply(
|
|
236
|
+
null,
|
|
237
|
+
app_opts);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const
|
|
2
|
+
_path =
|
|
3
|
+
require(
|
|
4
|
+
'path');
|
|
5
|
+
const
|
|
6
|
+
_output_dir =
|
|
7
|
+
_path.resolve(
|
|
8
|
+
__dirname);
|
|
9
|
+
const
|
|
10
|
+
_file_name =
|
|
11
|
+
"ahsi.js";
|
|
12
|
+
const
|
|
13
|
+
_output = {
|
|
14
|
+
path:
|
|
15
|
+
_output_dir,
|
|
16
|
+
filename:
|
|
17
|
+
_file_name
|
|
18
|
+
};
|
|
19
|
+
const
|
|
20
|
+
_yargs_ignore = {
|
|
21
|
+
resourceRegExp:
|
|
22
|
+
/^yargs$/
|
|
23
|
+
}
|
|
24
|
+
const
|
|
25
|
+
_yargs_helpers_ignore = {
|
|
26
|
+
resourceRegExp:
|
|
27
|
+
/^yargs\/helpers$/
|
|
28
|
+
}
|
|
29
|
+
const
|
|
30
|
+
_webpack =
|
|
31
|
+
require(
|
|
32
|
+
"webpack");
|
|
33
|
+
const
|
|
34
|
+
_ignore_plugin =
|
|
35
|
+
_webpack.IgnorePlugin;
|
|
36
|
+
const
|
|
37
|
+
_yargs_ignore_plugin =
|
|
38
|
+
new _ignore_plugin(
|
|
39
|
+
_yargs_ignore);
|
|
40
|
+
const
|
|
41
|
+
_yargs_helpers_ignore_plugin =
|
|
42
|
+
new _ignore_plugin(
|
|
43
|
+
_yargs_helpers_ignore);
|
|
44
|
+
module.exports = {
|
|
45
|
+
entry:
|
|
46
|
+
'./ahsi',
|
|
47
|
+
output:
|
|
48
|
+
_output,
|
|
49
|
+
optimization: {
|
|
50
|
+
moduleIds: 'deterministic',
|
|
51
|
+
},
|
|
52
|
+
resolve: {
|
|
53
|
+
fallback: {
|
|
54
|
+
"fs":
|
|
55
|
+
false,
|
|
56
|
+
"happy-opfs":
|
|
57
|
+
_path.resolve(
|
|
58
|
+
__dirname,
|
|
59
|
+
'node_modules/happy-opfs/dist/main.mjs'),
|
|
60
|
+
"path":
|
|
61
|
+
false,
|
|
62
|
+
"@std/path":
|
|
63
|
+
_path.resolve(
|
|
64
|
+
__dirname,
|
|
65
|
+
'node_modules/@std/path/mod.js'),
|
|
66
|
+
"fs-worker":
|
|
67
|
+
_path.resolve(
|
|
68
|
+
__dirname,
|
|
69
|
+
'node_modules/crash-bash/crash/bash/fs-worker'),
|
|
70
|
+
"yargs":
|
|
71
|
+
false,
|
|
72
|
+
"yargs/helpers":
|
|
73
|
+
false
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
externals:
|
|
77
|
+
{ yargs: 'yargs' },
|
|
78
|
+
plugins: [
|
|
79
|
+
_yargs_ignore_plugin,
|
|
80
|
+
_yargs_helpers_ignore_plugin
|
|
81
|
+
]
|
|
82
|
+
};
|