@naturalcycles/nodejs-lib 15.130.1 → 15.132.0

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.
Files changed (37) hide show
  1. package/dist/fs/fs2.d.ts +8 -8
  2. package/dist/fs/fs2.js +6 -8
  3. package/dist/index.d.ts +0 -1
  4. package/dist/index.js +0 -1
  5. package/dist/secret/secrets-encrypt.util.js +4 -7
  6. package/dist/security/crypto.util.d.ts +6 -6
  7. package/dist/security/hash.util.d.ts +12 -12
  8. package/dist/security/hash.util.js +12 -4
  9. package/dist/stream/index.d.ts +0 -1
  10. package/dist/stream/index.js +0 -1
  11. package/dist/stream/pipeline.d.ts +2 -7
  12. package/dist/stream/pipeline.js +0 -8
  13. package/dist/stream/transform/transformChunk.d.ts +2 -2
  14. package/dist/stream/transform/transformChunk.js +1 -0
  15. package/dist/validation/timezones.js +2 -2
  16. package/dist/zip/zip2.d.ts +25 -25
  17. package/dist/zip/zip2.js +2 -2
  18. package/dist/zip/zipWriter.d.ts +3 -3
  19. package/dist/zip/zipWriter.js +1 -1
  20. package/package.json +2 -2
  21. package/src/fs/fs2.ts +12 -15
  22. package/src/index.ts +0 -1
  23. package/src/secret/secrets-encrypt.util.ts +4 -7
  24. package/src/security/crypto.util.ts +19 -7
  25. package/src/security/hash.util.ts +25 -16
  26. package/src/stream/index.ts +0 -1
  27. package/src/stream/pipeline.ts +2 -11
  28. package/src/stream/transform/transformChunk.ts +3 -2
  29. package/src/validation/timezones.ts +2 -2
  30. package/src/zip/zip2.ts +30 -28
  31. package/src/zip/zipWriter.ts +9 -5
  32. package/dist/buffer/buffer.util.d.ts +0 -4
  33. package/dist/buffer/buffer.util.js +0 -10
  34. package/dist/stream/transform/transformWarmup.d.ts +0 -24
  35. package/dist/stream/transform/transformWarmup.js +0 -79
  36. package/src/buffer/buffer.util.ts +0 -12
  37. package/src/stream/transform/transformWarmup.ts +0 -105
package/dist/fs/fs2.d.ts CHANGED
@@ -18,24 +18,24 @@ declare class FS2 {
18
18
  * Convenience wrapper that defaults to utf-8 string output.
19
19
  */
20
20
  readTextAsync(filePath: string): Promise<string>;
21
- readBuffer(filePath: string): Buffer;
22
- readBufferAsync(filePath: string): Promise<Buffer>;
21
+ readBuffer(filePath: string): Buffer<ArrayBuffer>;
22
+ readBufferAsync(filePath: string): Promise<Buffer<ArrayBuffer>>;
23
23
  readJson<T = unknown>(filePath: string): T;
24
24
  readJsonAsync<T = unknown>(filePath: string): Promise<T>;
25
- writeFile(filePath: string, data: string | Buffer, opt?: WriteFileOptions): void;
26
- writeFileAsync(filePath: string, data: string | Buffer, opt?: WriteFileOptions): Promise<void>;
25
+ writeFile(filePath: string, data: string | Uint8Array, opt?: WriteFileOptions): void;
26
+ writeFileAsync(filePath: string, data: string | Uint8Array, opt?: WriteFileOptions): Promise<void>;
27
27
  writePrettyJson(filePath: string, data: any): void;
28
28
  writeJson(filePath: string, data: any, opt?: JsonOptions): void;
29
29
  writePrettyJsonAsync(filePath: string, data: any): Promise<void>;
30
30
  writeJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
31
- appendFile(filePath: string, data: string | Buffer): void;
32
- appendFileAsync(filePath: string, data: string | Buffer): Promise<void>;
31
+ appendFile(filePath: string, data: string | Uint8Array): void;
32
+ appendFileAsync(filePath: string, data: string | Uint8Array): Promise<void>;
33
33
  outputPrettyJson(filePath: string, data: any): void;
34
34
  outputJson(filePath: string, data: any, opt?: JsonOptions): void;
35
35
  outputPrettyJsonAsync(filePath: string, data: any): Promise<void>;
36
36
  outputJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
37
- outputFile(filePath: string, data: string | Buffer): void;
38
- outputFileAsync(filePath: string, data: string | Buffer): Promise<void>;
37
+ outputFile(filePath: string, data: string | Uint8Array): void;
38
+ outputFileAsync(filePath: string, data: string | Uint8Array): Promise<void>;
39
39
  pathExists(filePath: string): boolean;
40
40
  pathExistsAsync(filePath: string): Promise<boolean>;
41
41
  requireFileToExist(filePath: string): void;
package/dist/fs/fs2.js CHANGED
@@ -156,11 +156,9 @@ class FS2 {
156
156
  }
157
157
  catch (err) {
158
158
  // If the stat call above failed because the directory doesn't exist, create it
159
- if (err?.code === 'ENOENT') {
160
- this.ensureDir(dir);
161
- return;
162
- }
163
- throw err;
159
+ if (err?.code !== 'ENOENT')
160
+ throw err;
161
+ this.ensureDir(dir);
164
162
  }
165
163
  fs.writeFileSync(filePath, '');
166
164
  }
@@ -182,9 +180,9 @@ class FS2 {
182
180
  }
183
181
  catch (err) {
184
182
  // If the stat call above failed because the directory doesn't exist, create it
185
- if (err?.code === 'ENOENT')
186
- return await this.ensureDirAsync(dir);
187
- throw err;
183
+ if (err?.code !== 'ENOENT')
184
+ throw err;
185
+ await this.ensureDirAsync(dir);
188
186
  }
189
187
  await fsp.writeFile(filePath, '');
190
188
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './buffer/buffer.util.js';
2
1
  export * from './diff/tableDiff.js';
3
2
  export * from './infra/process.util.js';
4
3
  export * from './log/log.util.js';
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export * from './buffer/buffer.util.js';
2
1
  export * from './diff/tableDiff.js';
3
2
  export * from './infra/process.util.js';
4
3
  export * from './log/log.util.js';
@@ -10,13 +10,10 @@ import { encryptObject, encryptRandomIVBuffer } from '../security/crypto.util.js
10
10
  * Using provided encKey.
11
11
  */
12
12
  export function secretsEncrypt(pattern, file, encKeyBuffer, del = false, jsonMode = false) {
13
- const patterns = file
14
- ? [file]
15
- : [
16
- ...pattern,
17
- `!**/*.enc`, // excluding already encoded
18
- ];
19
- const filenames = globSync(patterns);
13
+ // Already encrypted files are filtered out: a `!**/*.enc` pattern only excludes them under the cwd
14
+ const filenames = file
15
+ ? globSync([file])
16
+ : globSync(pattern).filter(filename => !filename.endsWith('.enc'));
20
17
  let encFilename;
21
18
  filenames.forEach(filename => {
22
19
  if (jsonMode) {
@@ -2,35 +2,35 @@ import type { Base64String, StringMap } from '@naturalcycles/js-lib/types';
2
2
  /**
3
3
  * Using aes-256-cbc.
4
4
  */
5
- export declare function encryptRandomIVBuffer(input: Buffer, secretKeyBuffer: Buffer): Buffer;
5
+ export declare function encryptRandomIVBuffer(input: Uint8Array, secretKeyBuffer: Uint8Array): Buffer<ArrayBuffer>;
6
6
  /**
7
7
  * Using aes-256-cbc.
8
8
  */
9
- export declare function decryptRandomIVBuffer(input: Buffer, secretKeyBuffer: Buffer): Buffer;
9
+ export declare function decryptRandomIVBuffer(input: Uint8Array, secretKeyBuffer: Uint8Array): Buffer<ArrayBuffer>;
10
10
  /**
11
11
  * Decrypts all object values (base64 strings).
12
12
  * Returns object with decrypted values (utf8 strings).
13
13
  */
14
- export declare function decryptObject(obj: StringMap<Base64String>, secretKeyBuffer: Buffer): StringMap;
14
+ export declare function decryptObject(obj: StringMap<Base64String>, secretKeyBuffer: Uint8Array): StringMap;
15
15
  /**
16
16
  * Encrypts all object values (utf8 strings).
17
17
  * Returns object with encrypted values (base64 strings).
18
18
  */
19
- export declare function encryptObject(obj: StringMap, secretKeyBuffer: Buffer): StringMap<Base64String>;
19
+ export declare function encryptObject(obj: StringMap, secretKeyBuffer: Uint8Array): StringMap<Base64String>;
20
20
  /**
21
21
  * Using aes-256-cbc.
22
22
  *
23
23
  * Input is base64 string.
24
24
  * Output is utf8 string.
25
25
  */
26
- export declare function decryptString(str: Base64String, secretKeyBuffer: Buffer): string;
26
+ export declare function decryptString(str: Base64String, secretKeyBuffer: Uint8Array): string;
27
27
  /**
28
28
  * Using aes-256-cbc.
29
29
  *
30
30
  * Input is utf8 string.
31
31
  * Output is base64 string.
32
32
  */
33
- export declare function encryptString(str: string, secretKeyBuffer: Buffer): Base64String;
33
+ export declare function encryptString(str: string, secretKeyBuffer: Uint8Array): Base64String;
34
34
  /**
35
35
  * Wraps `crypto.timingSafeEqual` and allows it to be used with String inputs:
36
36
  *
@@ -1,18 +1,18 @@
1
1
  import type { BinaryToTextEncoding } from 'node:crypto';
2
2
  import type { Base64String, Base64UrlString } from '@naturalcycles/js-lib/types';
3
- export declare function md5(s: string | Buffer, outputEncoding?: BinaryToTextEncoding): string;
4
- export declare function md5AsBuffer(s: string | Buffer): Buffer;
5
- export declare function sha256(s: string | Buffer, outputEncoding?: BinaryToTextEncoding): string;
6
- export declare function sha256AsBuffer(s: string | Buffer): Buffer;
7
- export declare function hash(s: string | Buffer, algorithm: string, outputEncoding?: BinaryToTextEncoding): string;
8
- export declare function hashAsBuffer(s: string | Buffer, algorithm: string): Buffer;
9
- export declare function base64(s: string | Buffer): Base64String;
10
- export declare function base64Url(s: string | Buffer): Base64UrlString;
3
+ export declare function md5(s: string | Uint8Array, outputEncoding?: BinaryToTextEncoding): string;
4
+ export declare function md5AsBuffer(s: string | Uint8Array): Buffer<ArrayBuffer>;
5
+ export declare function sha256(s: string | Uint8Array, outputEncoding?: BinaryToTextEncoding): string;
6
+ export declare function sha256AsBuffer(s: string | Uint8Array): Buffer<ArrayBuffer>;
7
+ export declare function hash(s: string | Uint8Array, algorithm: string, outputEncoding?: BinaryToTextEncoding): string;
8
+ export declare function hashAsBuffer(s: string | Uint8Array, algorithm: string): Buffer<ArrayBuffer>;
9
+ export declare function base64(s: string | Uint8Array): Base64String;
10
+ export declare function base64Url(s: string | Uint8Array): Base64UrlString;
11
11
  export declare function base64ToString(strBase64: Base64String): string;
12
12
  export declare function base64UrlToString(strBase64Url: Base64UrlString): string;
13
- export declare function base64ToBuffer(strBase64: Base64String): Buffer;
14
- export declare function base64UrlToBuffer(strBase64Url: Base64UrlString): Buffer;
13
+ export declare function base64ToBuffer(strBase64: Base64String): Buffer<ArrayBuffer>;
14
+ export declare function base64UrlToBuffer(strBase64Url: Base64UrlString): Buffer<ArrayBuffer>;
15
15
  export declare function stringToBase64(s: string): Base64String;
16
16
  export declare function stringToBase64Url(s: string): Base64UrlString;
17
- export declare function bufferToBase64(b: Buffer): Base64String;
18
- export declare function bufferToBase64Url(b: Buffer): Base64UrlString;
17
+ export declare function bufferToBase64(b: Uint8Array): Base64String;
18
+ export declare function bufferToBase64Url(b: Uint8Array): Base64UrlString;
@@ -18,10 +18,14 @@ export function hashAsBuffer(s, algorithm) {
18
18
  return cryptoHash(algorithm, s, 'buffer');
19
19
  }
20
20
  export function base64(s) {
21
- return (typeof s === 'string' ? Buffer.from(s) : s).toString('base64');
21
+ if (typeof s === 'string')
22
+ return Buffer.from(s).toString('base64');
23
+ return bufferToBase64(s);
22
24
  }
23
25
  export function base64Url(s) {
24
- return (typeof s === 'string' ? Buffer.from(s) : s).toString('base64url');
26
+ if (typeof s === 'string')
27
+ return Buffer.from(s).toString('base64url');
28
+ return bufferToBase64Url(s);
25
29
  }
26
30
  export function base64ToString(strBase64) {
27
31
  return Buffer.from(strBase64, 'base64').toString('utf8');
@@ -41,9 +45,13 @@ export function stringToBase64(s) {
41
45
  export function stringToBase64Url(s) {
42
46
  return Buffer.from(s, 'utf8').toString('base64url');
43
47
  }
48
+ // Buffer#toString is faster than Uint8Array#toBase64 on small inputs (~1.3-1.7x up to ~512 bytes,
49
+ // measured on Node 26), hence the Buffer fast-path. On larger inputs they're on par.
44
50
  export function bufferToBase64(b) {
45
- return b.toString('base64');
51
+ return Buffer.isBuffer(b) ? b.toString('base64') : b.toBase64();
46
52
  }
47
53
  export function bufferToBase64Url(b) {
48
- return b.toString('base64url');
54
+ return Buffer.isBuffer(b)
55
+ ? b.toString('base64url')
56
+ : b.toBase64({ alphabet: 'base64url', omitPadding: true });
49
57
  }
@@ -24,7 +24,6 @@ export * from './transform/transformSplit.js';
24
24
  export * from './transform/transformTap.js';
25
25
  export * from './transform/transformThrottle.js';
26
26
  export * from './transform/transformThrottleByRSS.js';
27
- export * from './transform/transformWarmup.js';
28
27
  export * from './transform/worker/baseWorkerClass.js';
29
28
  export * from './transform/worker/transformMultiThreaded.js';
30
29
  export type * from './transform/worker/transformMultiThreaded.model.js';
@@ -23,7 +23,6 @@ export * from './transform/transformSplit.js';
23
23
  export * from './transform/transformTap.js';
24
24
  export * from './transform/transformThrottle.js';
25
25
  export * from './transform/transformThrottleByRSS.js';
26
- export * from './transform/transformWarmup.js';
27
26
  export * from './transform/worker/baseWorkerClass.js';
28
27
  export * from './transform/worker/transformMultiThreaded.js';
29
28
  export * from './writable/writableChunk.js';
@@ -1,7 +1,7 @@
1
1
  import type { Transform } from 'node:stream';
2
2
  import type { ReadableStream as WebReadableStream } from 'node:stream/web';
3
3
  import type { ZlibOptions, ZstdOptions } from 'node:zlib';
4
- import type { AbortableAsyncMapper, AbortableMapper, AsyncIndexedMapper, AsyncPredicate, END, IndexedMapper, Integer, NonNegativeInteger, PositiveInteger, Predicate, SKIP } from '@naturalcycles/js-lib/types';
4
+ import type { AbortableAsyncMapper, AbortableMapper, AsyncIndexedMapper, AsyncPredicate, END, IndexedMapper, Integer, NonEmptyArray, NonNegativeInteger, PositiveInteger, Predicate, SKIP } from '@naturalcycles/js-lib/types';
5
5
  import type { ReadableTyped, TransformOptions, TransformTyped, WritableTyped } from './stream.model.js';
6
6
  import type { TransformLogProgressOptions } from './transform/transformLogProgress.js';
7
7
  import type { TransformMapOptions } from './transform/transformMap.js';
@@ -10,7 +10,6 @@ import type { TransformMapSyncOptions } from './transform/transformMapSync.js';
10
10
  import type { TransformOffsetOptions } from './transform/transformOffset.js';
11
11
  import type { TransformThrottleOptions } from './transform/transformThrottle.js';
12
12
  import type { TransformThrottleByRSSOptions } from './transform/transformThrottleByRSS.js';
13
- import type { TransformWarmupOptions } from './transform/transformWarmup.js';
14
13
  export declare class Pipeline<T = unknown> {
15
14
  private readonly source;
16
15
  private transforms;
@@ -58,7 +57,7 @@ export declare class Pipeline<T = unknown> {
58
57
  * less clean than `.take()` on the source.
59
58
  */
60
59
  limit(limit: NonNegativeInteger | undefined): this;
61
- chunk(chunkSize: PositiveInteger, opt?: TransformOptions): Pipeline<T[]>;
60
+ chunk(chunkSize: PositiveInteger, opt?: TransformOptions): Pipeline<NonEmptyArray<T>>;
62
61
  flatten<TO>(this: Pipeline<readonly TO[]>): Pipeline<TO>;
63
62
  flattenIfNeeded(): Pipeline<T extends readonly (infer TO)[] ? TO : T>;
64
63
  logProgress(opt?: TransformLogProgressOptions): this;
@@ -72,10 +71,6 @@ export declare class Pipeline<T = unknown> {
72
71
  tapSync(fn: IndexedMapper<T, void>, opt?: TransformOptions): this;
73
72
  throttle(opt: TransformThrottleOptions): this;
74
73
  throttleByRSS(opt: TransformThrottleByRSSOptions): this;
75
- /**
76
- * @experimental to be removed after transformMap2 is stable
77
- */
78
- warmup(opt: TransformWarmupOptions): this;
79
74
  transform<TO>(transform: TransformTyped<T, TO>): Pipeline<TO>;
80
75
  /**
81
76
  * Helper method to add multiple transforms at once.
@@ -25,7 +25,6 @@ import { transformSplitOnNewline } from './transform/transformSplit.js';
25
25
  import { transformTap, transformTapSync } from './transform/transformTap.js';
26
26
  import { transformThrottle } from './transform/transformThrottle.js';
27
27
  import { transformThrottleByRSS } from './transform/transformThrottleByRSS.js';
28
- import { transformWarmup } from './transform/transformWarmup.js';
29
28
  import { writablePushToArray } from './writable/writablePushToArray.js';
30
29
  import { writableVoid } from './writable/writableVoid.js';
31
30
  export class Pipeline {
@@ -180,13 +179,6 @@ export class Pipeline {
180
179
  this.transforms.push(transformThrottleByRSS(opt));
181
180
  return this;
182
181
  }
183
- /**
184
- * @experimental to be removed after transformMap2 is stable
185
- */
186
- warmup(opt) {
187
- this.transforms.push(transformWarmup(opt));
188
- return this;
189
- }
190
182
  transform(transform) {
191
183
  this.transforms.push(transform);
192
184
  return this;
@@ -1,4 +1,4 @@
1
- import type { PositiveInteger } from '@naturalcycles/js-lib/types';
1
+ import type { NonEmptyArray, PositiveInteger } from '@naturalcycles/js-lib/types';
2
2
  import type { TransformOptions, TransformTyped } from '../stream.model.js';
3
3
  /**
4
4
  * Similar to RxJS bufferCount(),
@@ -8,4 +8,4 @@ import type { TransformOptions, TransformTyped } from '../stream.model.js';
8
8
  * `chunkSize` indicates how many items to include in each chunk.
9
9
  * Last chunk will contain the remaining items, possibly less than chunkSize.
10
10
  */
11
- export declare function transformChunk<IN = any>(chunkSize: PositiveInteger, opt?: TransformOptions): TransformTyped<IN, IN[]>;
11
+ export declare function transformChunk<IN = any>(chunkSize: PositiveInteger, opt?: TransformOptions): TransformTyped<IN, NonEmptyArray<IN>>;
@@ -8,6 +8,7 @@ import { Transform } from 'node:stream';
8
8
  * Last chunk will contain the remaining items, possibly less than chunkSize.
9
9
  */
10
10
  export function transformChunk(chunkSize, opt) {
11
+ // Only non-empty buffers are emitted
11
12
  let buf = [];
12
13
  return new Transform({
13
14
  objectMode: true,
@@ -1,4 +1,5 @@
1
1
  import { _uniq } from '@naturalcycles/js-lib/array';
2
+ import { Intl2 } from '@naturalcycles/js-lib/intl';
2
3
  // List extracted from Wikipedia (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
3
4
  // with the "Factory" value removed as its not working with our toolings
4
5
  const TIMEZONES_FROM_WIKI = [
@@ -600,8 +601,7 @@ const TIMEZONES_FROM_WIKI = [
600
601
  'WET',
601
602
  'Zulu',
602
603
  ];
603
- // oxlint-disable-next-line no-restricted-globals
604
- const TIMEZONES_FROM_JS = Intl.supportedValuesOf('timeZone');
604
+ const TIMEZONES_FROM_JS = Intl2.getSupportedTimezones();
605
605
  /**
606
606
  * A complicated merge of timezones from the underlying Javascript engine
607
607
  * and a list exported from Wikipedia.
@@ -4,59 +4,59 @@ import type { ZipEntry } from './zipReader.js';
4
4
  import { ZipWriter } from './zipWriter.js';
5
5
  import type { ZipFileEntry, ZipPathsOptions } from './zipWriter.js';
6
6
  declare class Zip2 {
7
- decompressZstdOrInflateToString(buf: Buffer): Promise<string>;
8
- decompressZstdOrInflateToStringSync(buf: Buffer): string;
7
+ decompressZstdOrInflateToString(buf: Uint8Array): Promise<string>;
8
+ decompressZstdOrInflateToStringSync(buf: Uint8Array): string;
9
9
  /**
10
10
  * Detects if Buffer is zstd-compressed.
11
11
  * Otherwise attempts to Inflate.
12
12
  */
13
- decompressZstdOrInflate(buf: Buffer): Promise<Buffer<ArrayBuffer>>;
14
- decompressZstdOrInflateSync(buf: Buffer): Buffer<ArrayBuffer>;
13
+ decompressZstdOrInflate(buf: Uint8Array): Promise<Buffer<ArrayBuffer>>;
14
+ decompressZstdOrInflateSync(buf: Uint8Array): Buffer<ArrayBuffer>;
15
15
  /**
16
16
  * deflateBuffer uses `deflate`.
17
17
  * It's 9 bytes shorter than `gzip`.
18
18
  */
19
- deflate(input: string | Buffer, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
19
+ deflate(input: string | Uint8Array, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
20
20
  /**
21
21
  * deflateSync uses `deflate`.
22
22
  * It's 9 bytes shorter than `gzip`.
23
23
  */
24
- deflateSync(input: string | Buffer, options?: ZlibOptions): Buffer<ArrayBuffer>;
25
- inflate(buf: Buffer, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
26
- inflateSync(buf: Buffer, options?: ZlibOptions): Buffer<ArrayBuffer>;
27
- inflateToString(buf: Buffer, options?: ZlibOptions): Promise<string>;
28
- inflateToStringSync(buf: Buffer, options?: ZlibOptions): string;
24
+ deflateSync(input: string | Uint8Array, options?: ZlibOptions): Buffer<ArrayBuffer>;
25
+ inflate(buf: Uint8Array, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
26
+ inflateSync(buf: Uint8Array, options?: ZlibOptions): Buffer<ArrayBuffer>;
27
+ inflateToString(buf: Uint8Array, options?: ZlibOptions): Promise<string>;
28
+ inflateToStringSync(buf: Uint8Array, options?: ZlibOptions): string;
29
29
  /**
30
30
  * gzipBuffer uses `gzip`
31
31
  * It's 9 bytes longer than `deflate`.
32
32
  */
33
- gzip(input: string | Buffer, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
33
+ gzip(input: string | Uint8Array, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
34
34
  /**
35
35
  * gzipBuffer uses `gzip`
36
36
  * It's 9 bytes longer than `deflate`.
37
37
  */
38
- gzipSync(input: string | Buffer, options?: ZlibOptions): Buffer<ArrayBuffer>;
39
- gunzip(buf: Buffer, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
40
- gunzipSync(buf: Buffer, options?: ZlibOptions): Buffer<ArrayBuffer>;
41
- gunzipToString(buf: Buffer, options?: ZlibOptions): Promise<string>;
42
- gunzipToStringSync(buf: Buffer, options?: ZlibOptions): string;
43
- zstdCompress(input: Buffer | string, level?: Integer, // defaults to 3
38
+ gzipSync(input: string | Uint8Array, options?: ZlibOptions): Buffer<ArrayBuffer>;
39
+ gunzip(buf: Uint8Array, options?: ZlibOptions): Promise<Buffer<ArrayBuffer>>;
40
+ gunzipSync(buf: Uint8Array, options?: ZlibOptions): Buffer<ArrayBuffer>;
41
+ gunzipToString(buf: Uint8Array, options?: ZlibOptions): Promise<string>;
42
+ gunzipToStringSync(buf: Uint8Array, options?: ZlibOptions): string;
43
+ zstdCompress(input: Uint8Array | string, level?: Integer, // defaults to 3
44
44
  options?: ZstdOptions): Promise<Buffer<ArrayBuffer>>;
45
- zstdCompressSync(input: Buffer | string, level?: Integer, // defaults to 3
45
+ zstdCompressSync(input: Uint8Array | string, level?: Integer, // defaults to 3
46
46
  options?: ZstdOptions): Buffer<ArrayBuffer>;
47
47
  zstdLevelToOptions(level: Integer | undefined, opt?: ZstdOptions): ZstdOptions;
48
- zstdDecompressToString(input: Buffer, options?: ZstdOptions): Promise<string>;
48
+ zstdDecompressToString(input: Uint8Array, options?: ZstdOptions): Promise<string>;
49
49
  /**
50
50
  * Warning! It leaks memory severely. Prefer sync.
51
51
  */
52
- zstdDecompress(input: Buffer, options?: ZstdOptions): Promise<Buffer<ArrayBuffer>>;
52
+ zstdDecompress(input: Uint8Array, options?: ZstdOptions): Promise<Buffer<ArrayBuffer>>;
53
53
  /**
54
54
  * Warning! It leaks memory severely. Prefer sync.
55
55
  */
56
- zstdDecompressToStringSync(input: Buffer, options?: ZstdOptions): string;
57
- zstdDecompressSync(input: Buffer, options?: ZstdOptions): Buffer<ArrayBuffer>;
58
- isZstdBuffer(input: Buffer): boolean;
59
- isGzipBuffer(input: Buffer): boolean;
56
+ zstdDecompressToStringSync(input: Uint8Array, options?: ZstdOptions): string;
57
+ zstdDecompressSync(input: Uint8Array, options?: ZstdOptions): Buffer<ArrayBuffer>;
58
+ isZstdBuffer(input: Uint8Array): boolean;
59
+ isGzipBuffer(input: Uint8Array): boolean;
60
60
  /**
61
61
  * Open a zip file and extract all of its entries into `destDir`, streaming each
62
62
  * file to disk. Directories are created as needed.
@@ -90,7 +90,7 @@ declare class Zip2 {
90
90
  *
91
91
  * For large archives or streamed inputs prefer {@link createZip} / {@link ZipWriter}.
92
92
  */
93
- createZipBuffer(entries: ZipFileEntry[]): Promise<Buffer>;
93
+ createZipBuffer(entries: ZipFileEntry[]): Promise<Buffer<ArrayBuffer>>;
94
94
  }
95
95
  export declare const zip2: Zip2;
96
96
  export {};
package/dist/zip/zip2.js CHANGED
@@ -122,7 +122,8 @@ class Zip2 {
122
122
  return zlib.zstdDecompressSync(input, options);
123
123
  }
124
124
  isZstdBuffer(input) {
125
- return input.readUInt32LE(0) === ZSTD_MAGIC_NUMBER;
125
+ // zstd magic number 0xFD2FB528, stored little-endian
126
+ return input[0] === 0x28 && input[1] === 0xb5 && input[2] === 0x2f && input[3] === 0xfd;
126
127
  }
127
128
  isGzipBuffer(input) {
128
129
  return input[0] === 0x1f && input[1] === 0x8b;
@@ -177,4 +178,3 @@ class Zip2 {
177
178
  }
178
179
  }
179
180
  export const zip2 = new Zip2();
180
- const ZSTD_MAGIC_NUMBER = 0xfd2fb528;
@@ -6,7 +6,7 @@ import type { UnixTimestamp } from '@naturalcycles/js-lib/types';
6
6
  *
7
7
  * Each input path may be a file (added directly) or a directory (walked
8
8
  * recursively; all nested files are added). By default an entry's name is its
9
- * path relative to its input's parent directory, so `zipFiles(['./photos'], 'out.zip')`
9
+ * path relative to its input's parent directory, so `zipPaths(['./photos'], 'out.zip')`
10
10
  * stores entries under `photos/...`. Override the base via {@link ZipPathsOptions.baseDir}.
11
11
  *
12
12
  * Files discovered by walking a directory are added in deterministic (sorted)
@@ -25,7 +25,7 @@ export declare function zipPaths(paths: string[], outputZipFilePath: string, opt
25
25
  *
26
26
  * For large archives or streamed inputs prefer {@link createZip} / {@link ZipWriter}.
27
27
  */
28
- export declare function createZipBuffer(entries: ZipFileEntry[]): Promise<Buffer>;
28
+ export declare function createZipBuffer(entries: ZipFileEntry[]): Promise<Buffer<ArrayBuffer>>;
29
29
  /**
30
30
  * Options for {@link zipPaths}.
31
31
  */
@@ -69,7 +69,7 @@ export declare class ZipWriter implements AsyncDisposable {
69
69
  * Add an in-memory buffer as a file entry.
70
70
  * The CRC-32 and sizes are computed up front and written inline (no data descriptor).
71
71
  */
72
- addBuffer(data: Buffer, fileName: string, opt?: ZipWriterEntryOptions): Promise<void>;
72
+ addBuffer(data: Uint8Array, fileName: string, opt?: ZipWriterEntryOptions): Promise<void>;
73
73
  /**
74
74
  * Add a file from disk, streaming its contents. The entry's mtime and mode
75
75
  * default to the file's own (override via `opt`). If `fileName` is omitted,
@@ -38,7 +38,7 @@ const deflateRawAsync = promisify(zlib.deflateRaw.bind(zlib));
38
38
  *
39
39
  * Each input path may be a file (added directly) or a directory (walked
40
40
  * recursively; all nested files are added). By default an entry's name is its
41
- * path relative to its input's parent directory, so `zipFiles(['./photos'], 'out.zip')`
41
+ * path relative to its input's parent directory, so `zipPaths(['./photos'], 'out.zip')`
42
42
  * stores entries under `photos/...`. Override the base via {@link ZipPathsOptions.baseDir}.
43
43
  *
44
44
  * Files discovered by walking a directory are added in deterministic (sorted)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.130.1",
4
+ "version": "15.132.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@standard-schema/spec": "^1",
@@ -65,7 +65,7 @@
65
65
  "directory": "packages/nodejs-lib"
66
66
  },
67
67
  "engines": {
68
- "node": ">=24.10.0"
68
+ "node": ">=26.12.1"
69
69
  },
70
70
  "description": "Standard library for Node.js",
71
71
  "author": "Natural Cycles Team",
package/src/fs/fs2.ts CHANGED
@@ -47,11 +47,11 @@ class FS2 {
47
47
  return await fsp.readFile(filePath, 'utf8')
48
48
  }
49
49
 
50
- readBuffer(filePath: string): Buffer {
50
+ readBuffer(filePath: string): Buffer<ArrayBuffer> {
51
51
  return fs.readFileSync(filePath)
52
52
  }
53
53
 
54
- async readBufferAsync(filePath: string): Promise<Buffer> {
54
+ async readBufferAsync(filePath: string): Promise<Buffer<ArrayBuffer>> {
55
55
  return await fsp.readFile(filePath)
56
56
  }
57
57
 
@@ -65,13 +65,13 @@ class FS2 {
65
65
  return _jsonParse(str)
66
66
  }
67
67
 
68
- writeFile(filePath: string, data: string | Buffer, opt?: WriteFileOptions): void {
68
+ writeFile(filePath: string, data: string | Uint8Array, opt?: WriteFileOptions): void {
69
69
  fs.writeFileSync(filePath, data, opt)
70
70
  }
71
71
 
72
72
  async writeFileAsync(
73
73
  filePath: string,
74
- data: string | Buffer,
74
+ data: string | Uint8Array,
75
75
  opt?: WriteFileOptions,
76
76
  ): Promise<void> {
77
77
  await fsp.writeFile(filePath, data, opt)
@@ -95,11 +95,11 @@ class FS2 {
95
95
  await fsp.writeFile(filePath, str)
96
96
  }
97
97
 
98
- appendFile(filePath: string, data: string | Buffer): void {
98
+ appendFile(filePath: string, data: string | Uint8Array): void {
99
99
  fs.appendFileSync(filePath, data)
100
100
  }
101
101
 
102
- async appendFileAsync(filePath: string, data: string | Buffer): Promise<void> {
102
+ async appendFileAsync(filePath: string, data: string | Uint8Array): Promise<void> {
103
103
  await fsp.appendFile(filePath, data)
104
104
  }
105
105
 
@@ -121,7 +121,7 @@ class FS2 {
121
121
  await this.outputFileAsync(filePath, str)
122
122
  }
123
123
 
124
- outputFile(filePath: string, data: string | Buffer): void {
124
+ outputFile(filePath: string, data: string | Uint8Array): void {
125
125
  const dirPath = path.dirname(filePath)
126
126
  if (!fs.existsSync(dirPath)) {
127
127
  this.ensureDir(dirPath)
@@ -130,7 +130,7 @@ class FS2 {
130
130
  fs.writeFileSync(filePath, data)
131
131
  }
132
132
 
133
- async outputFileAsync(filePath: string, data: string | Buffer): Promise<void> {
133
+ async outputFileAsync(filePath: string, data: string | Uint8Array): Promise<void> {
134
134
  const dirPath = path.dirname(filePath)
135
135
  if (!(await this.pathExistsAsync(dirPath))) {
136
136
  await this.ensureDirAsync(dirPath)
@@ -188,11 +188,8 @@ class FS2 {
188
188
  }
189
189
  } catch (err) {
190
190
  // If the stat call above failed because the directory doesn't exist, create it
191
- if ((err as any)?.code === 'ENOENT') {
192
- this.ensureDir(dir)
193
- return
194
- }
195
- throw err
191
+ if ((err as any)?.code !== 'ENOENT') throw err
192
+ this.ensureDir(dir)
196
193
  }
197
194
 
198
195
  fs.writeFileSync(filePath, '')
@@ -214,8 +211,8 @@ class FS2 {
214
211
  }
215
212
  } catch (err) {
216
213
  // If the stat call above failed because the directory doesn't exist, create it
217
- if ((err as any)?.code === 'ENOENT') return await this.ensureDirAsync(dir)
218
- throw err
214
+ if ((err as any)?.code !== 'ENOENT') throw err
215
+ await this.ensureDirAsync(dir)
219
216
  }
220
217
 
221
218
  await fsp.writeFile(filePath, '')
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './buffer/buffer.util.js'
2
1
  export * from './diff/tableDiff.js'
3
2
  export * from './infra/process.util.js'
4
3
  export * from './log/log.util.js'
@@ -25,13 +25,10 @@ export function secretsEncrypt(
25
25
  del = false,
26
26
  jsonMode = false,
27
27
  ): void {
28
- const patterns = file
29
- ? [file]
30
- : [
31
- ...pattern,
32
- `!**/*.enc`, // excluding already encoded
33
- ]
34
- const filenames = globSync(patterns)
28
+ // Already encrypted files are filtered out: a `!**/*.enc` pattern only excludes them under the cwd
29
+ const filenames = file
30
+ ? globSync([file])
31
+ : globSync(pattern).filter(filename => !filename.endsWith('.enc'))
35
32
  let encFilename: string
36
33
 
37
34
  filenames.forEach(filename => {