encoding-tools 0.0.9 → 0.0.11

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/encoding-tools CHANGED
@@ -36,6 +36,9 @@ const
36
36
  _txt2bin_module =
37
37
  require(
38
38
  "./libtxt2bin");
39
+ const
40
+ _input_texts_check =
41
+ _txt2bin_module._input_texts_check;
39
42
  const
40
43
  _txt2bin =
41
44
  _txt2bin_module._txt2bin;
@@ -43,6 +46,8 @@ const
43
46
  module.exports = {
44
47
  _bin2txt:
45
48
  _bin2txt,
49
+ _input_texts_check:
50
+ _input_texts_check,
46
51
  _txt2bin:
47
52
  _txt2bin
48
53
  };
package/libbin2txt CHANGED
@@ -135,7 +135,8 @@ async function
135
135
  _out,
136
136
  _buffer_size_bytes) {
137
137
  let
138
- _msg;
138
+ _msg,
139
+ _output_files;
139
140
  const
140
141
  _size_max =
141
142
  0;
@@ -153,56 +154,69 @@ async function
153
154
  Math.ceil(
154
155
  _in_size_bytes /
155
156
  _buffer_size_bytes);
156
- _msg =
157
- `Splitting file '${_in}' in ` +
158
- `'${_blocks_total}' blocks of ` +
159
- `'${_buffer_size_bytes}' bytes.`;
160
- _msg_info(
161
- _msg);
162
- const
163
- _split_opts = [
164
- _in,
165
- `${_out}.block.`,
166
- _blocks_total,
167
- _size_max
168
- ];
169
- const
157
+ if ( 1 < _blocks_total ) {
158
+ _msg =
159
+ `Splitting file '${_in}' in ` +
160
+ `'${_blocks_total}' blocks of ` +
161
+ `'${_buffer_size_bytes}' bytes.`;
162
+ _msg_info(
163
+ _msg);
164
+ const
165
+ _split_opts = [
166
+ _in,
167
+ `${_out}.block.`,
168
+ _blocks_total,
169
+ _size_max
170
+ ];
170
171
  _output_files =
171
172
  await _split.apply(
172
173
  null,
173
174
  _split_opts);
174
- _msg =
175
- "Done.";
176
- _msg_info(
177
- _msg);
175
+ _msg =
176
+ "Done.";
177
+ _msg_info(
178
+ _msg);
179
+ }
180
+ else {
181
+ _output_files = [
182
+ _in
183
+ ];
184
+ }
178
185
  return _output_files;
179
186
  }
180
187
 
181
- function
188
+ async function
182
189
  _base64_block_encode(
183
190
  _file) {
184
191
  let
185
192
  _string;
193
+ const
194
+ _cat_opts = {
195
+ "encoding":
196
+ null,
197
+ "flag":
198
+ "r"};
186
199
  const
187
200
  _content =
188
201
  _cat(
189
- _file);
202
+ _file,
203
+ _cat_opts);
190
204
  if ( typeof window === 'undefined' &&
191
205
  ( typeof global !== 'undefined' &&
192
206
  global.global === global ) &&
193
207
  typeof __webpack_require__ !== 'function' ) {
194
- const
195
- _buffer =
196
- Buffer.from(
197
- _content);
208
+ // const
209
+ // _buffer =
210
+ // await Buffer.from(
211
+ // _content);
198
212
  _string =
199
- _buffer.toString(
213
+ _content.toString(
200
214
  "base64");
201
215
  }
202
216
  else {
203
217
  _string =
204
- btoa(
205
- _string);
218
+ await btoa(
219
+ _content);
206
220
  }
207
221
  return _string;
208
222
  }
@@ -230,6 +244,7 @@ async function
230
244
  _chunk_current +
231
245
  _total /
232
246
  _length);
247
+ console.log("prefix", _prefix);
233
248
  if ( _chunks < 2 ) {
234
249
  _out =
235
250
  _prefix;
@@ -264,7 +279,7 @@ async function
264
279
  _msg_info(
265
280
  _msg);
266
281
  if ( _chunk < _chunks ) {
267
- _printf(
282
+ _file_write(
268
283
  _out,
269
284
  _cut);
270
285
  }
@@ -282,7 +297,7 @@ async function
282
297
  _msg);
283
298
  _file_write(
284
299
  _out,
285
- _cut);
300
+ `${_cut}\n`);
286
301
  }
287
302
  }
288
303
  }
@@ -307,7 +322,7 @@ async function
307
322
  _msg;
308
323
  const
309
324
  _txt =
310
- _base64_block_encode(
325
+ await _base64_block_encode(
311
326
  _block);
312
327
  _msg =
313
328
  `Block '${_block}' encoded ` +
@@ -374,12 +389,11 @@ async function
374
389
  _amount_only) {
375
390
  let
376
391
  _block,
377
- _chunk_current,
378
- _chunks_total,
379
392
  _block_current,
380
393
  _block_last,
394
+ _chunk_current,
395
+ _chunks_total,
381
396
  _msg,
382
- _rm_args,
383
397
  _worker;
384
398
  if ( typeof window !== 'undefined' ) {
385
399
  const
@@ -423,7 +437,7 @@ async function
423
437
  }
424
438
  if ( _format === "base64" ) {
425
439
  _chunk_current =
426
- _base64_encode(
440
+ await _base64_encode(
427
441
  _block,
428
442
  _chunk_current,
429
443
  _length,
@@ -444,11 +458,18 @@ async function
444
458
  1);
445
459
  }
446
460
  }
461
+ const
462
+ _rm_args =
463
+ [];
447
464
  for ( _block of _blocks ) {
448
- _rm_args = [
449
- _block
450
- ];
451
- _rm(
465
+ if ( _block != _in ) {
466
+ _rm_args.push(
467
+ _block);
468
+ }
469
+ }
470
+ if ( 0 < _rm_args.length ) {
471
+ _rm.apply(
472
+ null,
452
473
  _rm_args);
453
474
  }
454
475
  if ( _amount_only === "true" ) {
package/libtxt2bin CHANGED
@@ -88,6 +88,11 @@ const
88
88
  const
89
89
  _file_append =
90
90
  _libcrash._file_append;
91
+ /* global
92
+ _file_exists */
93
+ const
94
+ _file_exists =
95
+ _libcrash._file_exists;
91
96
  /* global
92
97
  _file_read */
93
98
  const
@@ -179,7 +184,7 @@ async function
179
184
  _msg);
180
185
  }
181
186
 
182
- function
187
+ async function
183
188
  _base64_decode(
184
189
  _output_file,
185
190
  _input_files,
@@ -202,9 +207,14 @@ function
202
207
  _input_files[
203
208
  0];
204
209
  if ( 0 < _input_files.length ) {
210
+ const
211
+ _tmp_dir =
212
+ await _mktemp();
213
+ console.log(
214
+ _tmp_dir);
205
215
  _txt =
206
216
  _path_join( [
207
- _mktemp(),
217
+ _tmp_dir,
208
218
  "merge.base64" ]);
209
219
  _assemble(
210
220
  _txt,
@@ -222,11 +232,48 @@ function
222
232
  }
223
233
 
224
234
  function
235
+ _input_texts_check(
236
+ _input_texts) {
237
+ let
238
+ _file,
239
+ _input_file_exists;
240
+ for ( _file of _input_texts ) {
241
+ _input_file_exists =
242
+ _file_exists(
243
+ _file);
244
+ if ( ! _input_file_exists ) {
245
+ const
246
+ _msg =
247
+ `Input file '${_file}' does not ` +
248
+ `exist.`;
249
+ _msg_error(
250
+ _msg,
251
+ 1);
252
+ }
253
+ }
254
+ }
255
+
256
+ async function
225
257
  _txt2bin(
226
258
  _output_file,
227
259
  _encoding_format,
228
260
  _argument_type,
229
- _input_files) {
261
+ _input_files,
262
+ _input_files_sanity_check) {
263
+ const
264
+ _input_files_sanity_check_type =
265
+ typeof(
266
+ _input_files_sanity_check);
267
+ if ( _input_files_sanity_check_type == "undefined" ||
268
+ _input_files_sanity_check == "" ||
269
+ _input_files_sanity_check == "true" ) {
270
+ _input_files_sanity_check =
271
+ true;
272
+ }
273
+ if ( _input_files_sanity_check == "false" ) {
274
+ _input_files_sanity_check =
275
+ false;
276
+ }
230
277
  if ( _argument_type == "list" ) {
231
278
  const
232
279
  _list =
@@ -237,8 +284,12 @@ function
237
284
  _list).split(
238
285
  "\n");
239
286
  }
287
+ if ( _input_files_sanity_check ) {
288
+ _input_texts_check(
289
+ _input_files);
290
+ }
240
291
  if ( _encoding_format == "base64" ) {
241
- _base64_decode(
292
+ await _base64_decode(
242
293
  _output_file,
243
294
  _input_files,
244
295
  _argument_type);
@@ -246,6 +297,8 @@ function
246
297
  }
247
298
 
248
299
  module.exports = {
300
+ _input_texts_check:
301
+ _input_texts_check,
249
302
  _txt2bin:
250
303
  _txt2bin
251
304
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name":
3
3
  "encoding-tools",
4
4
  "version":
5
- "0.0.9",
5
+ "0.0.11",
6
6
  "description":
7
7
  "A multi-language collection of encoding tools.",
8
8
  "funding": {
@@ -60,7 +60,7 @@
60
60
  },
61
61
  "devDependencies": {
62
62
  "crash-js-webpack":
63
- "^0.0.19",
63
+ "^0.0.25",
64
64
  "eslint":
65
65
  "^10.3.0",
66
66
  "globals":
@@ -80,7 +80,9 @@
80
80
  "base64-stream":
81
81
  "^1.0.0",
82
82
  "crash-js":
83
- "^0.1.125",
83
+ "^0.1.130",
84
+ "fs":
85
+ "npm:@themartiancompany/fs@^0.0.8",
84
86
  "tmcsplit":
85
87
  "^0.0.10",
86
88
  "yargs":
package/txt2bin CHANGED
@@ -122,6 +122,11 @@ const
122
122
  _encoding_tools =
123
123
  require(
124
124
  "./encoding-tools");
125
+ /* global
126
+ _input_texts_check */
127
+ const
128
+ _input_texts_check =
129
+ _encoding_tools._input_texts_check;
125
130
  /* global
126
131
  _txt2bin */
127
132
  const
@@ -180,13 +185,14 @@ function
180
185
  _line;
181
186
  const
182
187
  _text = [
183
- ` Call date: ${make_date}`,
188
+ ` Make date: ${make_date}`,
184
189
  ` Runtime environment: ${runtime_environment}`,
185
190
  ` Argument type: ${argument_type}`,
186
191
  ` Encoding format: ${encoding_format}`,
187
192
  ` Output file: ${output_file}`,
188
193
  ` Input text file(s): ${input_texts}`,
189
194
  ];
195
+ _msg_info("perche");
190
196
  for ( _line of _text ) {
191
197
  _msg_info(
192
198
  _line);
@@ -251,6 +257,8 @@ function
251
257
  argument_type =
252
258
  "file";
253
259
  }
260
+ _input_texts_check(
261
+ input_texts);
254
262
  }
255
263
 
256
264
  function
@@ -279,11 +287,13 @@ function
279
287
  "y";
280
288
  _help_display =
281
289
  false;
282
- if ( "h" in _argv ) {
290
+ if ( _argv[
291
+ "h"]) {
283
292
  _help_display =
284
293
  true;
285
294
  }
286
- if ( "help" in _argv ) {
295
+ if ( _argv[
296
+ "help"] ) {
287
297
  _help_display =
288
298
  true;
289
299
  }
@@ -343,11 +353,13 @@ function
343
353
  _argv[
344
354
  "encoding-format"];
345
355
  }
346
- if ( "v" in _argv ) {
356
+ if ( _argv[
357
+ "v"] ) {
347
358
  verbose =
348
359
  true;
349
360
  }
350
- if ( "verbose" in _argv ) {
361
+ if ( _argv[
362
+ "verbose"] ) {
351
363
  verbose =
352
364
  true;
353
365
  }
@@ -397,6 +409,7 @@ if ( _cmdline_check(
397
409
  else {
398
410
  _url_parse();
399
411
  }
412
+ _overrides_set();
400
413
  _config_show();
401
414
  app_opts = [
402
415
  output_file,