nbis-wrapper-js 0.0.1 → 0.1.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 (54) hide show
  1. package/README.md +34 -0
  2. package/dist/src/an2ktool.d.ts +12 -0
  3. package/dist/src/an2ktool.js +40 -0
  4. package/dist/src/bozorth3.d.ts +16 -0
  5. package/dist/src/bozorth3.js +152 -2
  6. package/dist/src/chkan2k.d.ts +2 -0
  7. package/dist/src/chkan2k.js +30 -0
  8. package/dist/src/cjp2k.d.ts +10 -0
  9. package/dist/src/cjp2k.js +51 -0
  10. package/dist/src/cjpeg.d.ts +8 -0
  11. package/dist/src/cjpeg.js +61 -0
  12. package/dist/src/cjpegb.d.ts +8 -0
  13. package/dist/src/cjpegb.js +25 -0
  14. package/dist/src/cjpegl.d.ts +8 -0
  15. package/dist/src/cjpegl.js +28 -0
  16. package/dist/src/cwsq.d.ts +8 -0
  17. package/dist/src/cwsq.js +22 -0
  18. package/dist/src/datainfo.d.ts +2 -0
  19. package/dist/src/datainfo.js +12 -0
  20. package/dist/src/djp2k.d.ts +10 -0
  21. package/dist/src/djp2k.js +52 -0
  22. package/dist/src/djpeg.d.ts +8 -0
  23. package/dist/src/djpeg.js +64 -0
  24. package/dist/src/djpegb.d.ts +9 -0
  25. package/dist/src/djpegb.js +26 -0
  26. package/dist/src/djpegl.d.ts +9 -0
  27. package/dist/src/djpegl.js +26 -0
  28. package/dist/src/dwsq.d.ts +9 -0
  29. package/dist/src/dwsq.js +23 -0
  30. package/dist/src/intr2not.d.ts +8 -0
  31. package/dist/src/intr2not.js +22 -0
  32. package/dist/src/jpegtran.d.ts +8 -0
  33. package/dist/src/jpegtran.js +82 -0
  34. package/dist/src/mindtct.d.ts +12 -0
  35. package/dist/src/mindtct.js +44 -0
  36. package/dist/src/nfiq.d.ts +8 -0
  37. package/dist/src/nfiq.js +39 -0
  38. package/dist/src/not2intr.d.ts +13 -0
  39. package/dist/src/not2intr.js +22 -0
  40. package/dist/src/rdjpgcom.d.ts +3 -0
  41. package/dist/src/rdjpgcom.js +17 -0
  42. package/dist/src/rdwsqcom.d.ts +2 -0
  43. package/dist/src/rdwsqcom.js +12 -0
  44. package/dist/src/rgb2ycc.d.ts +8 -0
  45. package/dist/src/rgb2ycc.js +25 -0
  46. package/dist/src/temp-io.d.ts +15 -0
  47. package/dist/src/temp-io.js +102 -0
  48. package/dist/src/wrjpgcom.d.ts +7 -0
  49. package/dist/src/wrjpgcom.js +26 -0
  50. package/dist/src/wrwsqcom.d.ts +8 -0
  51. package/dist/src/wrwsqcom.js +21 -0
  52. package/dist/src/ycc2rgb.d.ts +13 -0
  53. package/dist/src/ycc2rgb.js +25 -0
  54. package/package.json +1 -1
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Cjpegl = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
9
10
  function buildRawAttr(raw) {
10
11
  const attrs = [raw.width, raw.height, raw.depth];
11
12
  if (raw.ppi != null) {
@@ -50,5 +51,32 @@ class Cjpegl {
50
51
  stderr: result.stderr
51
52
  };
52
53
  }
54
+ async compressStream(outputExtension, input, options = {}) {
55
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
56
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
57
+ const args = [outputExtension, inputPath];
58
+ if (options.rawIn) {
59
+ args.push('-raw_in', buildRawAttr(options.rawIn));
60
+ }
61
+ if (options.nonInterleaved) {
62
+ args.push('-nonintrlv');
63
+ }
64
+ if (options.yCbCr) {
65
+ args.push('-YCbCr', buildYCbCr(options.yCbCr));
66
+ }
67
+ if (options.commentFile) {
68
+ args.push(options.commentFile);
69
+ }
70
+ const result = (0, nbis_runtime_1.runNbis)('cjpegl', args);
71
+ (0, nbis_runtime_1.assertSuccess)(result, 'cjpegl');
72
+ const outputPath = replaceExtension(inputPath, outputExtension);
73
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
74
+ return {
75
+ stdout: result.stdout,
76
+ stderr: result.stderr,
77
+ outputBuffer
78
+ };
79
+ });
80
+ }
53
81
  }
54
82
  exports.Cjpegl = Cjpegl;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type CwsqOptions = {
2
3
  rawIn?: {
3
4
  width: number;
@@ -12,7 +13,14 @@ export type CwsqResult = {
12
13
  stdout: string;
13
14
  stderr: string;
14
15
  };
16
+ export type CwsqStreamOptions = CwsqOptions & StreamIoOptions;
17
+ export type CwsqStreamResult = {
18
+ stdout: string;
19
+ stderr: string;
20
+ outputBuffer?: Buffer;
21
+ };
15
22
  export declare class Cwsq {
16
23
  version(): string;
17
24
  compress(bitrate: number, outputExtension: string, imagePath: string, options?: CwsqOptions): CwsqResult;
25
+ compressStream(bitrate: number, outputExtension: string, input: StreamInput, options?: CwsqStreamOptions): Promise<CwsqStreamResult>;
18
26
  }
package/dist/src/cwsq.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Cwsq = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
9
10
  function buildRawAttr(raw) {
10
11
  const attrs = [raw.width, raw.height, raw.depth];
11
12
  if (raw.ppi != null) {
@@ -40,5 +41,26 @@ class Cwsq {
40
41
  stderr: result.stderr
41
42
  };
42
43
  }
44
+ async compressStream(bitrate, outputExtension, input, options = {}) {
45
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
46
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
47
+ const args = [String(bitrate), outputExtension, inputPath];
48
+ if (options.rawIn) {
49
+ args.push('-raw_in', buildRawAttr(options.rawIn));
50
+ }
51
+ if (options.commentFile) {
52
+ args.push(options.commentFile);
53
+ }
54
+ const result = (0, nbis_runtime_1.runNbis)('cwsq', args);
55
+ (0, nbis_runtime_1.assertSuccess)(result, 'cwsq');
56
+ const outputPath = replaceExtension(inputPath, outputExtension);
57
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
58
+ return {
59
+ stdout: result.stdout,
60
+ stderr: result.stderr,
61
+ outputBuffer
62
+ };
63
+ });
64
+ }
43
65
  }
44
66
  exports.Cwsq = Cwsq;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamInputOptions } from './temp-io';
1
2
  export type DatainfoResult = {
2
3
  stdout: string;
3
4
  stderr: string;
@@ -5,4 +6,5 @@ export type DatainfoResult = {
5
6
  export declare class Datainfo {
6
7
  version(): string;
7
8
  report(dataFile: string): DatainfoResult;
9
+ reportStream(input: StreamInput, options?: StreamInputOptions): Promise<DatainfoResult>;
8
10
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Datainfo = void 0;
4
4
  const nbis_runtime_1 = require("./nbis-runtime");
5
+ const temp_io_1 = require("./temp-io");
5
6
  class Datainfo {
6
7
  version() {
7
8
  const result = (0, nbis_runtime_1.runNbis)('datainfo', ['-version']);
@@ -16,5 +17,16 @@ class Datainfo {
16
17
  stderr: result.stderr
17
18
  };
18
19
  }
20
+ async reportStream(input, options = {}) {
21
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
22
+ const dataFile = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
23
+ const result = (0, nbis_runtime_1.runNbis)('datainfo', [dataFile]);
24
+ (0, nbis_runtime_1.assertSuccess)(result, 'datainfo');
25
+ return {
26
+ stdout: result.stdout,
27
+ stderr: result.stderr
28
+ };
29
+ });
30
+ }
19
31
  }
20
32
  exports.Datainfo = Datainfo;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type Djp2kOptions = {
2
3
  inputPath?: string;
3
4
  outputPath?: string;
@@ -14,7 +15,16 @@ export type Djp2kResult = {
14
15
  stdout: string;
15
16
  stderr: string;
16
17
  };
18
+ export type Djp2kStreamOptions = Omit<Djp2kOptions, 'inputPath' | 'outputPath' | 'imageDir'> & StreamIoOptions & {
19
+ outputExtension?: string;
20
+ };
21
+ export type Djp2kStreamResult = {
22
+ stdout: string;
23
+ stderr: string;
24
+ outputBuffer?: Buffer;
25
+ };
17
26
  export declare class Djp2k {
18
27
  version(): string;
19
28
  decompress(options: Djp2kOptions): Djp2kResult;
29
+ decompressStream(input: StreamInput, options?: Djp2kStreamOptions): Promise<Djp2kStreamResult>;
20
30
  }
package/dist/src/djp2k.js CHANGED
@@ -1,7 +1,18 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Djp2k = void 0;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
10
+ function normalizeExtension(extension) {
11
+ if (!extension) {
12
+ return '';
13
+ }
14
+ return extension.startsWith('.') ? extension : `.${extension}`;
15
+ }
5
16
  class Djp2k {
6
17
  version() {
7
18
  const result = (0, nbis_runtime_1.runNbis)('djp2k', ['-h']);
@@ -49,5 +60,46 @@ class Djp2k {
49
60
  stderr: result.stderr
50
61
  };
51
62
  }
63
+ async decompressStream(input, options = {}) {
64
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
65
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
66
+ const outputExtension = options.outputExtension || options.outputFormat;
67
+ if (!outputExtension) {
68
+ throw new Error('djp2k stream output requires outputExtension or outputFormat.');
69
+ }
70
+ const outputPath = path_1.default.join(tempDir, `output${normalizeExtension(outputExtension)}`);
71
+ const args = [];
72
+ if (options.outputFormat) {
73
+ args.push('-OutFor', options.outputFormat);
74
+ }
75
+ if (options.reduceFactor != null) {
76
+ args.push('-r', String(options.reduceFactor));
77
+ }
78
+ if (options.layers != null) {
79
+ args.push('-l', String(options.layers));
80
+ }
81
+ if (options.indexFile) {
82
+ args.push('-x', options.indexFile);
83
+ }
84
+ if (options.decodeArea) {
85
+ args.push('-d', options.decodeArea);
86
+ }
87
+ if (options.tileNumber != null) {
88
+ args.push('-t', String(options.tileNumber));
89
+ }
90
+ if (options.extraArgs) {
91
+ args.push(...options.extraArgs);
92
+ }
93
+ args.push('-i', inputPath, '-o', outputPath);
94
+ const result = (0, nbis_runtime_1.runNbis)('djp2k', args);
95
+ (0, nbis_runtime_1.assertSuccess)(result, 'djp2k');
96
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
97
+ return {
98
+ stdout: result.stdout,
99
+ stderr: result.stderr,
100
+ outputBuffer
101
+ };
102
+ });
103
+ }
52
104
  }
53
105
  exports.Djp2k = Djp2k;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type DjpegOptions = {
2
3
  colors?: number;
3
4
  fast?: boolean;
@@ -20,6 +21,13 @@ export type DjpegResult = {
20
21
  stderr: string;
21
22
  outputPath?: string;
22
23
  };
24
+ export type DjpegStreamOptions = Omit<DjpegOptions, 'outputPath'> & StreamIoOptions;
25
+ export type DjpegStreamResult = {
26
+ stdout: string;
27
+ stderr: string;
28
+ outputBuffer?: Buffer;
29
+ };
23
30
  export declare class Djpeg {
24
31
  decompress(inputPath: string, options?: DjpegOptions): DjpegResult;
32
+ decompressStream(input: StreamInput, options?: DjpegStreamOptions): Promise<DjpegStreamResult>;
25
33
  }
package/dist/src/djpeg.js CHANGED
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Djpeg = void 0;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
5
10
  class Djpeg {
6
11
  decompress(inputPath, options = {}) {
7
12
  const args = [];
@@ -59,5 +64,64 @@ class Djpeg {
59
64
  outputPath: options.outputPath
60
65
  };
61
66
  }
67
+ async decompressStream(input, options = {}) {
68
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
69
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
70
+ const outputPath = path_1.default.join(tempDir, 'output');
71
+ const args = [];
72
+ if (options.colors != null) {
73
+ args.push('-colors', String(options.colors));
74
+ }
75
+ if (options.fast) {
76
+ args.push('-fast');
77
+ }
78
+ if (options.grayscale) {
79
+ args.push('-grayscale');
80
+ }
81
+ if (options.scale) {
82
+ args.push('-scale', options.scale);
83
+ }
84
+ if (options.format) {
85
+ args.push(`-${options.format}`);
86
+ }
87
+ if (options.dct) {
88
+ args.push('-dct', options.dct);
89
+ }
90
+ if (options.dither) {
91
+ args.push('-dither', options.dither);
92
+ }
93
+ if (options.mapFile) {
94
+ args.push('-map', options.mapFile);
95
+ }
96
+ if (options.noSmooth) {
97
+ args.push('-nosmooth');
98
+ }
99
+ if (options.onePass) {
100
+ args.push('-onepass');
101
+ }
102
+ if (options.maxMemory) {
103
+ args.push('-maxmemory', options.maxMemory);
104
+ }
105
+ args.push('-outfile', outputPath);
106
+ if (options.verbose) {
107
+ args.push('-verbose');
108
+ }
109
+ if (options.debug) {
110
+ args.push('-debug');
111
+ }
112
+ if (options.extraArgs) {
113
+ args.push(...options.extraArgs);
114
+ }
115
+ args.push(inputPath);
116
+ const result = (0, nbis_runtime_1.runNbis)('djpeg', args);
117
+ (0, nbis_runtime_1.assertSuccess)(result, 'djpeg');
118
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
119
+ return {
120
+ stdout: result.stdout,
121
+ stderr: result.stderr,
122
+ outputBuffer
123
+ };
124
+ });
125
+ }
62
126
  }
63
127
  exports.Djpeg = Djpeg;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type DjpegbOptions = {
2
3
  rawOut?: boolean;
3
4
  nonInterleaved?: boolean;
@@ -8,7 +9,15 @@ export type DjpegbResult = {
8
9
  stdout: string;
9
10
  stderr: string;
10
11
  };
12
+ export type DjpegbStreamOptions = DjpegbOptions & StreamIoOptions;
13
+ export type DjpegbStreamResult = {
14
+ stdout: string;
15
+ stderr: string;
16
+ outputBuffer?: Buffer;
17
+ nistcomBuffer?: Buffer;
18
+ };
11
19
  export declare class Djpegb {
12
20
  version(): string;
13
21
  decompress(outputExtension: string, imagePath: string, options?: DjpegbOptions): DjpegbResult;
22
+ decompressStream(outputExtension: string, input: StreamInput, options?: DjpegbStreamOptions): Promise<DjpegbStreamResult>;
14
23
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Djpegb = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
9
10
  function replaceExtension(inputPath, outputExtension) {
10
11
  const parsed = path_1.default.parse(inputPath);
11
12
  const ext = outputExtension.startsWith('.') ? outputExtension : `.${outputExtension}`;
@@ -35,5 +36,30 @@ class Djpegb {
35
36
  stderr: result.stderr
36
37
  };
37
38
  }
39
+ async decompressStream(outputExtension, input, options = {}) {
40
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
41
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
42
+ const args = [outputExtension, inputPath];
43
+ if (options.rawOut) {
44
+ args.push('-raw_out');
45
+ }
46
+ if (options.nonInterleaved) {
47
+ args.push('-nonintrlv');
48
+ }
49
+ const result = (0, nbis_runtime_1.runNbis)('djpegb', args);
50
+ (0, nbis_runtime_1.assertSuccess)(result, 'djpegb');
51
+ const outputPath = replaceExtension(inputPath, outputExtension);
52
+ const parsed = path_1.default.parse(inputPath);
53
+ const nistcomPath = path_1.default.join(parsed.dir, `${parsed.name}.ncm`);
54
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
55
+ const nistcomBuffer = await (0, temp_io_1.readFileIfExists)(nistcomPath);
56
+ return {
57
+ stdout: result.stdout,
58
+ stderr: result.stderr,
59
+ outputBuffer,
60
+ nistcomBuffer
61
+ };
62
+ });
63
+ }
38
64
  }
39
65
  exports.Djpegb = Djpegb;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type DjpeglOptions = {
2
3
  rawOut?: boolean;
3
4
  nonInterleaved?: boolean;
@@ -8,7 +9,15 @@ export type DjpeglResult = {
8
9
  stdout: string;
9
10
  stderr: string;
10
11
  };
12
+ export type DjpeglStreamOptions = DjpeglOptions & StreamIoOptions;
13
+ export type DjpeglStreamResult = {
14
+ stdout: string;
15
+ stderr: string;
16
+ outputBuffer?: Buffer;
17
+ nistcomBuffer?: Buffer;
18
+ };
11
19
  export declare class Djpegl {
12
20
  version(): string;
13
21
  decompress(outputExtension: string, imagePath: string, options?: DjpeglOptions): DjpeglResult;
22
+ decompressStream(outputExtension: string, input: StreamInput, options?: DjpeglStreamOptions): Promise<DjpeglStreamResult>;
14
23
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Djpegl = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
9
10
  function replaceExtension(inputPath, outputExtension) {
10
11
  const parsed = path_1.default.parse(inputPath);
11
12
  const ext = outputExtension.startsWith('.') ? outputExtension : `.${outputExtension}`;
@@ -35,5 +36,30 @@ class Djpegl {
35
36
  stderr: result.stderr
36
37
  };
37
38
  }
39
+ async decompressStream(outputExtension, input, options = {}) {
40
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
41
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
42
+ const args = [outputExtension, inputPath];
43
+ if (options.rawOut) {
44
+ args.push('-raw_out');
45
+ }
46
+ if (options.nonInterleaved) {
47
+ args.push('-nonintrlv');
48
+ }
49
+ const result = (0, nbis_runtime_1.runNbis)('djpegl', args);
50
+ (0, nbis_runtime_1.assertSuccess)(result, 'djpegl');
51
+ const outputPath = replaceExtension(inputPath, outputExtension);
52
+ const parsed = path_1.default.parse(inputPath);
53
+ const nistcomPath = path_1.default.join(parsed.dir, `${parsed.name}.ncm`);
54
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
55
+ const nistcomBuffer = await (0, temp_io_1.readFileIfExists)(nistcomPath);
56
+ return {
57
+ stdout: result.stdout,
58
+ stderr: result.stderr,
59
+ outputBuffer,
60
+ nistcomBuffer
61
+ };
62
+ });
63
+ }
38
64
  }
39
65
  exports.Djpegl = Djpegl;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type DwsqOptions = {
2
3
  rawOut?: boolean;
3
4
  };
@@ -7,7 +8,15 @@ export type DwsqResult = {
7
8
  stdout: string;
8
9
  stderr: string;
9
10
  };
11
+ export type DwsqStreamOptions = DwsqOptions & StreamIoOptions;
12
+ export type DwsqStreamResult = {
13
+ stdout: string;
14
+ stderr: string;
15
+ outputBuffer?: Buffer;
16
+ nistcomBuffer?: Buffer;
17
+ };
10
18
  export declare class Dwsq {
11
19
  version(): string;
12
20
  decompress(outputExtension: string, imagePath: string, options?: DwsqOptions): DwsqResult;
21
+ decompressStream(outputExtension: string, input: StreamInput, options?: DwsqStreamOptions): Promise<DwsqStreamResult>;
13
22
  }
package/dist/src/dwsq.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Dwsq = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
9
10
  function replaceExtension(inputPath, outputExtension) {
10
11
  const parsed = path_1.default.parse(inputPath);
11
12
  const ext = outputExtension.startsWith('.') ? outputExtension : `.${outputExtension}`;
@@ -32,5 +33,27 @@ class Dwsq {
32
33
  stderr: result.stderr
33
34
  };
34
35
  }
36
+ async decompressStream(outputExtension, input, options = {}) {
37
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
38
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
39
+ const args = [outputExtension, inputPath];
40
+ if (options.rawOut) {
41
+ args.push('-raw_out');
42
+ }
43
+ const result = (0, nbis_runtime_1.runNbis)('dwsq', args);
44
+ (0, nbis_runtime_1.assertSuccess)(result, 'dwsq');
45
+ const outputPath = replaceExtension(inputPath, outputExtension);
46
+ const parsed = path_1.default.parse(inputPath);
47
+ const nistcomPath = path_1.default.join(parsed.dir, `${parsed.name}.ncm`);
48
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
49
+ const nistcomBuffer = await (0, temp_io_1.readFileIfExists)(nistcomPath);
50
+ return {
51
+ stdout: result.stdout,
52
+ stderr: result.stderr,
53
+ outputBuffer,
54
+ nistcomBuffer
55
+ };
56
+ });
57
+ }
35
58
  }
36
59
  exports.Dwsq = Dwsq;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type Intr2notOptions = {
2
3
  rawIn?: {
3
4
  width: number;
@@ -16,7 +17,14 @@ export type Intr2notResult = {
16
17
  stdout: string;
17
18
  stderr: string;
18
19
  };
20
+ export type Intr2notStreamOptions = Intr2notOptions & StreamIoOptions;
21
+ export type Intr2notStreamResult = {
22
+ stdout: string;
23
+ stderr: string;
24
+ outputBuffer?: Buffer;
25
+ };
19
26
  export declare class Intr2not {
20
27
  version(): string;
21
28
  convert(outputExtension: string, imagePath: string, options?: Intr2notOptions): Intr2notResult;
29
+ convertStream(outputExtension: string, input: StreamInput, options?: Intr2notStreamOptions): Promise<Intr2notStreamResult>;
22
30
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Intr2not = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
9
10
  function buildRawAttr(raw) {
10
11
  const attrs = [raw.width, raw.height, raw.depth];
11
12
  if (raw.ppi != null) {
@@ -44,5 +45,26 @@ class Intr2not {
44
45
  stderr: result.stderr
45
46
  };
46
47
  }
48
+ async convertStream(outputExtension, input, options = {}) {
49
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
50
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
51
+ const args = [outputExtension, inputPath];
52
+ if (options.rawIn) {
53
+ args.push('-raw_in', buildRawAttr(options.rawIn));
54
+ }
55
+ if (options.yCbCr) {
56
+ args.push('-YCbCr', buildYCbCr(options.yCbCr));
57
+ }
58
+ const result = (0, nbis_runtime_1.runNbis)('intr2not', args);
59
+ (0, nbis_runtime_1.assertSuccess)(result, 'intr2not');
60
+ const outputPath = replaceExtension(inputPath, outputExtension);
61
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
62
+ return {
63
+ stdout: result.stdout,
64
+ stderr: result.stderr,
65
+ outputBuffer
66
+ };
67
+ });
68
+ }
47
69
  }
48
70
  exports.Intr2not = Intr2not;
@@ -1,3 +1,4 @@
1
+ import type { StreamInput, StreamIoOptions } from './temp-io';
1
2
  export type JpegtranOptions = {
2
3
  optimize?: boolean;
3
4
  progressive?: boolean;
@@ -18,7 +19,14 @@ export type JpegtranResult = {
18
19
  stderr: string;
19
20
  outputPath?: string;
20
21
  };
22
+ export type JpegtranStreamOptions = Omit<JpegtranOptions, 'outputPath'> & StreamIoOptions;
23
+ export type JpegtranStreamResult = {
24
+ stdout: string;
25
+ stderr: string;
26
+ outputBuffer?: Buffer;
27
+ };
21
28
  export declare class Jpegtran {
22
29
  version(): string;
23
30
  transform(inputPath: string, options?: JpegtranOptions): JpegtranResult;
31
+ transformStream(input: StreamInput, options?: JpegtranStreamOptions): Promise<JpegtranStreamResult>;
24
32
  }
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Jpegtran = void 0;
7
+ const path_1 = __importDefault(require("path"));
4
8
  const nbis_runtime_1 = require("./nbis-runtime");
9
+ const temp_io_1 = require("./temp-io");
5
10
  class Jpegtran {
6
11
  version() {
7
12
  const result = (0, nbis_runtime_1.runNbis)('jpegtran', ['-version']);
@@ -84,5 +89,82 @@ class Jpegtran {
84
89
  outputPath: options.outputPath
85
90
  };
86
91
  }
92
+ async transformStream(input, options = {}) {
93
+ return (0, temp_io_1.withTempDir)(async (tempDir) => {
94
+ const inputPath = await (0, temp_io_1.writeTempInput)(tempDir, input, options);
95
+ const outputPath = path_1.default.join(tempDir, 'output.jpg');
96
+ const args = [];
97
+ if (options.optimize) {
98
+ args.push('-optimize');
99
+ }
100
+ if (options.progressive) {
101
+ args.push('-progressive');
102
+ }
103
+ if (options.restart != null) {
104
+ args.push('-restart', String(options.restart));
105
+ }
106
+ if (options.scansFile) {
107
+ args.push('-scans', options.scansFile);
108
+ }
109
+ if (options.transform) {
110
+ switch (options.transform) {
111
+ case 'flip-horizontal':
112
+ args.push('-flip', 'horizontal');
113
+ break;
114
+ case 'flip-vertical':
115
+ args.push('-flip', 'vertical');
116
+ break;
117
+ case 'rotate-90':
118
+ args.push('-rotate', '90');
119
+ break;
120
+ case 'rotate-180':
121
+ args.push('-rotate', '180');
122
+ break;
123
+ case 'rotate-270':
124
+ args.push('-rotate', '270');
125
+ break;
126
+ case 'transpose':
127
+ args.push('-transpose');
128
+ break;
129
+ case 'transverse':
130
+ args.push('-transverse');
131
+ break;
132
+ default:
133
+ break;
134
+ }
135
+ }
136
+ if (options.trim) {
137
+ args.push('-trim');
138
+ }
139
+ if (options.grayscale) {
140
+ args.push('-grayscale');
141
+ }
142
+ if (options.copy) {
143
+ args.push('-copy', options.copy);
144
+ }
145
+ if (options.maxMemory) {
146
+ args.push('-maxmemory', options.maxMemory);
147
+ }
148
+ args.push('-outfile', outputPath);
149
+ if (options.verbose) {
150
+ args.push('-verbose');
151
+ }
152
+ if (options.debug) {
153
+ args.push('-debug');
154
+ }
155
+ if (options.extraArgs) {
156
+ args.push(...options.extraArgs);
157
+ }
158
+ args.push(inputPath);
159
+ const result = (0, nbis_runtime_1.runNbis)('jpegtran', args);
160
+ (0, nbis_runtime_1.assertSuccess)(result, 'jpegtran');
161
+ const outputBuffer = await (0, temp_io_1.deliverTempOutput)(outputPath, options);
162
+ return {
163
+ stdout: result.stdout,
164
+ stderr: result.stderr,
165
+ outputBuffer
166
+ };
167
+ });
168
+ }
87
169
  }
88
170
  exports.Jpegtran = Jpegtran;