@spinajs/fs 2.0.481 → 2.0.484
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/lib/cjs/cli/cat.d.ts +11 -0
- package/lib/cjs/cli/cat.d.ts.map +1 -0
- package/lib/cjs/cli/cat.js +40 -0
- package/lib/cjs/cli/cat.js.map +1 -0
- package/lib/cjs/cli/cp.d.ts +11 -0
- package/lib/cjs/cli/cp.d.ts.map +1 -0
- package/lib/cjs/cli/cp.js +41 -0
- package/lib/cjs/cli/cp.js.map +1 -0
- package/lib/cjs/cli/download.d.ts +7 -0
- package/lib/cjs/cli/download.d.ts.map +1 -0
- package/lib/cjs/cli/download.js +39 -0
- package/lib/cjs/cli/download.js.map +1 -0
- package/lib/cjs/cli/exists.d.ts +7 -0
- package/lib/cjs/cli/exists.d.ts.map +1 -0
- package/lib/cjs/cli/exists.js +39 -0
- package/lib/cjs/cli/exists.js.map +1 -0
- package/lib/cjs/cli/fs.d.ts +11 -0
- package/lib/cjs/cli/fs.d.ts.map +1 -1
- package/lib/cjs/cli/fs.js +47 -21
- package/lib/cjs/cli/fs.js.map +1 -1
- package/lib/cjs/cli/hash.d.ts +11 -0
- package/lib/cjs/cli/hash.d.ts.map +1 -0
- package/lib/cjs/cli/hash.js +40 -0
- package/lib/cjs/cli/hash.js.map +1 -0
- package/lib/cjs/cli/info.d.ts +7 -0
- package/lib/cjs/cli/info.d.ts.map +1 -0
- package/lib/cjs/cli/info.js +45 -0
- package/lib/cjs/cli/info.js.map +1 -0
- package/lib/cjs/cli/ls.d.ts +7 -0
- package/lib/cjs/cli/ls.d.ts.map +1 -0
- package/lib/cjs/cli/ls.js +40 -0
- package/lib/cjs/cli/ls.js.map +1 -0
- package/lib/cjs/cli/mkdir.d.ts +7 -0
- package/lib/cjs/cli/mkdir.d.ts.map +1 -0
- package/lib/cjs/cli/mkdir.js +39 -0
- package/lib/cjs/cli/mkdir.js.map +1 -0
- package/lib/cjs/cli/mv.d.ts +11 -0
- package/lib/cjs/cli/mv.d.ts.map +1 -0
- package/lib/cjs/cli/mv.js +41 -0
- package/lib/cjs/cli/mv.js.map +1 -0
- package/lib/cjs/cli/rm.d.ts +1 -6
- package/lib/cjs/cli/rm.d.ts.map +1 -1
- package/lib/cjs/cli/rm.js +14 -4
- package/lib/cjs/cli/rm.js.map +1 -1
- package/lib/cjs/cli/stat.d.ts +1 -5
- package/lib/cjs/cli/stat.d.ts.map +1 -1
- package/lib/cjs/cli/stat.js +20 -3
- package/lib/cjs/cli/stat.js.map +1 -1
- package/lib/cjs/cli/unzip.d.ts +11 -0
- package/lib/cjs/cli/unzip.d.ts.map +1 -0
- package/lib/cjs/cli/unzip.js +47 -0
- package/lib/cjs/cli/unzip.js.map +1 -0
- package/lib/cjs/cli/upload.d.ts +7 -0
- package/lib/cjs/cli/upload.d.ts.map +1 -0
- package/lib/cjs/cli/upload.js +40 -0
- package/lib/cjs/cli/upload.js.map +1 -0
- package/lib/cjs/cli/write.d.ts +13 -0
- package/lib/cjs/cli/write.d.ts.map +1 -0
- package/lib/cjs/cli/write.js +54 -0
- package/lib/cjs/cli/write.js.map +1 -0
- package/lib/cjs/cli/zip.d.ts +12 -0
- package/lib/cjs/cli/zip.d.ts.map +1 -0
- package/lib/cjs/cli/zip.js +51 -0
- package/lib/cjs/cli/zip.js.map +1 -0
- package/lib/cjs/config/fs.d.ts +9 -0
- package/lib/cjs/config/fs.d.ts.map +1 -0
- package/lib/cjs/config/fs.js +22 -0
- package/lib/cjs/config/fs.js.map +1 -0
- package/lib/cjs/file-hasher.d.ts +85 -5
- package/lib/cjs/file-hasher.d.ts.map +1 -1
- package/lib/cjs/file-hasher.js +106 -14
- package/lib/cjs/file-hasher.js.map +1 -1
- package/lib/cjs/file-info.d.ts +94 -5
- package/lib/cjs/file-info.d.ts.map +1 -1
- package/lib/cjs/file-info.js +267 -73
- package/lib/cjs/file-info.js.map +1 -1
- package/lib/cjs/fp.d.ts +80 -2
- package/lib/cjs/fp.d.ts.map +1 -1
- package/lib/cjs/fp.js +149 -3
- package/lib/cjs/fp.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +7 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +89 -12
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js +13 -13
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/local-provider.d.ts +51 -6
- package/lib/cjs/local-provider.d.ts.map +1 -1
- package/lib/cjs/local-provider.js +254 -76
- package/lib/cjs/local-provider.js.map +1 -1
- package/lib/cjs/temp-cleanup-strategy.d.ts +70 -0
- package/lib/cjs/temp-cleanup-strategy.d.ts.map +1 -0
- package/lib/cjs/temp-cleanup-strategy.js +157 -0
- package/lib/cjs/temp-cleanup-strategy.js.map +1 -0
- package/lib/cjs/temp-provider.d.ts +59 -0
- package/lib/cjs/temp-provider.d.ts.map +1 -0
- package/lib/cjs/temp-provider.js +150 -0
- package/lib/cjs/temp-provider.js.map +1 -0
- package/lib/mjs/cli/cat.d.ts +11 -0
- package/lib/mjs/cli/cat.d.ts.map +1 -0
- package/lib/mjs/cli/cat.js +37 -0
- package/lib/mjs/cli/cat.js.map +1 -0
- package/lib/mjs/cli/cp.d.ts +11 -0
- package/lib/mjs/cli/cp.d.ts.map +1 -0
- package/lib/mjs/cli/cp.js +38 -0
- package/lib/mjs/cli/cp.js.map +1 -0
- package/lib/mjs/cli/download.d.ts +7 -0
- package/lib/mjs/cli/download.d.ts.map +1 -0
- package/lib/mjs/cli/download.js +36 -0
- package/lib/mjs/cli/download.js.map +1 -0
- package/lib/mjs/cli/exists.d.ts +7 -0
- package/lib/mjs/cli/exists.d.ts.map +1 -0
- package/lib/mjs/cli/exists.js +36 -0
- package/lib/mjs/cli/exists.js.map +1 -0
- package/lib/mjs/cli/fs.d.ts +11 -1
- package/lib/mjs/cli/fs.d.ts.map +1 -1
- package/lib/mjs/cli/fs.js +43 -22
- package/lib/mjs/cli/fs.js.map +1 -1
- package/lib/mjs/cli/hash.d.ts +11 -0
- package/lib/mjs/cli/hash.d.ts.map +1 -0
- package/lib/mjs/cli/hash.js +37 -0
- package/lib/mjs/cli/hash.js.map +1 -0
- package/lib/mjs/cli/info.d.ts +7 -0
- package/lib/mjs/cli/info.d.ts.map +1 -0
- package/lib/mjs/cli/info.js +42 -0
- package/lib/mjs/cli/info.js.map +1 -0
- package/lib/mjs/cli/ls.d.ts +7 -0
- package/lib/mjs/cli/ls.d.ts.map +1 -0
- package/lib/mjs/cli/ls.js +37 -0
- package/lib/mjs/cli/ls.js.map +1 -0
- package/lib/mjs/cli/mkdir.d.ts +7 -0
- package/lib/mjs/cli/mkdir.d.ts.map +1 -0
- package/lib/mjs/cli/mkdir.js +36 -0
- package/lib/mjs/cli/mkdir.js.map +1 -0
- package/lib/mjs/cli/mv.d.ts +11 -0
- package/lib/mjs/cli/mv.d.ts.map +1 -0
- package/lib/mjs/cli/mv.js +38 -0
- package/lib/mjs/cli/mv.js.map +1 -0
- package/lib/mjs/cli/rm.d.ts +1 -6
- package/lib/mjs/cli/rm.d.ts.map +1 -1
- package/lib/mjs/cli/rm.js +15 -5
- package/lib/mjs/cli/rm.js.map +1 -1
- package/lib/mjs/cli/stat.d.ts +1 -5
- package/lib/mjs/cli/stat.d.ts.map +1 -1
- package/lib/mjs/cli/stat.js +21 -4
- package/lib/mjs/cli/stat.js.map +1 -1
- package/lib/mjs/cli/unzip.d.ts +11 -0
- package/lib/mjs/cli/unzip.d.ts.map +1 -0
- package/lib/mjs/cli/unzip.js +44 -0
- package/lib/mjs/cli/unzip.js.map +1 -0
- package/lib/mjs/cli/upload.d.ts +7 -0
- package/lib/mjs/cli/upload.d.ts.map +1 -0
- package/lib/mjs/cli/upload.js +37 -0
- package/lib/mjs/cli/upload.js.map +1 -0
- package/lib/mjs/cli/write.d.ts +13 -0
- package/lib/mjs/cli/write.d.ts.map +1 -0
- package/lib/mjs/cli/write.js +51 -0
- package/lib/mjs/cli/write.js.map +1 -0
- package/lib/mjs/cli/zip.d.ts +12 -0
- package/lib/mjs/cli/zip.d.ts.map +1 -0
- package/lib/mjs/cli/zip.js +48 -0
- package/lib/mjs/cli/zip.js.map +1 -0
- package/lib/mjs/config/fs.d.ts +9 -0
- package/lib/mjs/config/fs.d.ts.map +1 -0
- package/lib/mjs/config/fs.js +20 -0
- package/lib/mjs/config/fs.js.map +1 -0
- package/lib/mjs/file-hasher.d.ts +85 -5
- package/lib/mjs/file-hasher.d.ts.map +1 -1
- package/lib/mjs/file-hasher.js +106 -14
- package/lib/mjs/file-hasher.js.map +1 -1
- package/lib/mjs/file-info.d.ts +94 -5
- package/lib/mjs/file-info.d.ts.map +1 -1
- package/lib/mjs/file-info.js +233 -73
- package/lib/mjs/file-info.js.map +1 -1
- package/lib/mjs/fp.d.ts +80 -2
- package/lib/mjs/fp.d.ts.map +1 -1
- package/lib/mjs/fp.js +135 -4
- package/lib/mjs/fp.js.map +1 -1
- package/lib/mjs/index.d.ts +2 -1
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +8 -3
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +89 -12
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js +13 -13
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/local-provider.d.ts +51 -6
- package/lib/mjs/local-provider.d.ts.map +1 -1
- package/lib/mjs/local-provider.js +257 -79
- package/lib/mjs/local-provider.js.map +1 -1
- package/lib/mjs/temp-cleanup-strategy.d.ts +70 -0
- package/lib/mjs/temp-cleanup-strategy.d.ts.map +1 -0
- package/lib/mjs/temp-cleanup-strategy.js +153 -0
- package/lib/mjs/temp-cleanup-strategy.js.map +1 -0
- package/lib/mjs/temp-provider.d.ts +59 -0
- package/lib/mjs/temp-provider.d.ts.map +1 -0
- package/lib/mjs/temp-provider.js +147 -0
- package/lib/mjs/temp-provider.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +12 -6
- package/lib/cjs/local-temp-provider.d.ts +0 -18
- package/lib/cjs/local-temp-provider.d.ts.map +0 -1
- package/lib/cjs/local-temp-provider.js +0 -63
- package/lib/cjs/local-temp-provider.js.map +0 -1
- package/lib/mjs/local-temp-provider.d.ts +0 -18
- package/lib/mjs/local-temp-provider.d.ts.map +0 -1
- package/lib/mjs/local-temp-provider.js +0 -60
- package/lib/mjs/local-temp-provider.js.map +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { CliCommand, Command, Argument, Option } from '@spinajs/cli';
|
|
11
|
+
import { Logger, Log } from '@spinajs/log-common';
|
|
12
|
+
import { _fs } from '../fp.js';
|
|
13
|
+
import { IOFail } from '@spinajs/exceptions';
|
|
14
|
+
import { ensureProviders } from './fs.js';
|
|
15
|
+
let FsUnzipCommand = class FsUnzipCommand extends CliCommand {
|
|
16
|
+
async execute(fsName, src, dst, options) {
|
|
17
|
+
await ensureProviders();
|
|
18
|
+
try {
|
|
19
|
+
const provider = _fs(fsName)();
|
|
20
|
+
if (!provider) {
|
|
21
|
+
throw new IOFail(`Filesystem ${fsName} not found`);
|
|
22
|
+
}
|
|
23
|
+
const dstFs = options.dstFs ? _fs(options.dstFs)() : undefined;
|
|
24
|
+
const out = await provider.unzip(src, dst, dstFs);
|
|
25
|
+
this.Log.success(`Extracted ${src} -> ${out} ( fs: ${options.dstFs ?? fsName} )`);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
this.Log.error(`Cannot unzip ${src} on ${fsName}: ${err.message}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
__decorate([
|
|
33
|
+
Logger('fs'),
|
|
34
|
+
__metadata("design:type", Log)
|
|
35
|
+
], FsUnzipCommand.prototype, "Log", void 0);
|
|
36
|
+
FsUnzipCommand = __decorate([
|
|
37
|
+
Command('fs-unzip', 'Extracts a zip archive'),
|
|
38
|
+
Argument('fs', true, 'Filesystem that contains the archive'),
|
|
39
|
+
Argument('src', true, 'Path to the zip file ( relative to source fs )'),
|
|
40
|
+
Argument('dst', false, 'Destination directory ( relative to destination fs )'),
|
|
41
|
+
Option('-d, --dst-fs <dstFs>', false, 'Destination filesystem to extract into ( defaults to source fs )')
|
|
42
|
+
], FsUnzipCommand);
|
|
43
|
+
export { FsUnzipCommand };
|
|
44
|
+
//# sourceMappingURL=unzip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unzip.js","sourceRoot":"","sources":["../../../src/cli/unzip.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE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E,kEAAkE,CAAC;GAC7F,cAAc,CAsB1B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CliCommand } from '@spinajs/cli';
|
|
2
|
+
import { Log } from '@spinajs/log-common';
|
|
3
|
+
export declare class FsUploadCommand extends CliCommand {
|
|
4
|
+
protected Log: Log;
|
|
5
|
+
execute(fsName: string, src: string, dst?: string): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/cli/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAU,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAIlD,qBAIa,eAAgB,SAAQ,UAAU;IAE7C,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAEN,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAU/E"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { CliCommand, Command, Argument } from '@spinajs/cli';
|
|
11
|
+
import { Logger, Log } from '@spinajs/log-common';
|
|
12
|
+
import { _upload } from '../fp.js';
|
|
13
|
+
import { ensureProviders } from './fs.js';
|
|
14
|
+
let FsUploadCommand = class FsUploadCommand extends CliCommand {
|
|
15
|
+
async execute(fsName, src, dst) {
|
|
16
|
+
await ensureProviders();
|
|
17
|
+
try {
|
|
18
|
+
await _upload(src, dst, fsName);
|
|
19
|
+
this.Log.success(`Uploaded ${src} -> ${dst ?? '( basename )'} ( fs: ${fsName} )`);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
this.Log.error(`Cannot upload ${src} to ${fsName}: ${err.message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
__decorate([
|
|
27
|
+
Logger('fs'),
|
|
28
|
+
__metadata("design:type", Log)
|
|
29
|
+
], FsUploadCommand.prototype, "Log", void 0);
|
|
30
|
+
FsUploadCommand = __decorate([
|
|
31
|
+
Command('fs-upload', 'Uploads a local file into a filesystem'),
|
|
32
|
+
Argument('fs', true, 'Destination filesystem name'),
|
|
33
|
+
Argument('src', true, 'Local source file ( absolute path )'),
|
|
34
|
+
Argument('dst', false, 'Destination path ( defaults to source file name )')
|
|
35
|
+
], FsUploadCommand);
|
|
36
|
+
export { FsUploadCommand };
|
|
37
|
+
//# sourceMappingURL=upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.js","sourceRoot":"","sources":["../../../src/cli/upload.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAMnC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,UAAU;IAItC,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,GAAW,EAAE,GAAY;QAC5D,MAAM,eAAe,EAAE,CAAC;QAExB,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;YAChC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,GAAG,OAAO,GAAG,IAAI,cAAc,UAAU,MAAM,IAAI,CAAC,CAAC;QACpF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,GAAG,OAAO,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF,CAAA;AAZW;IADT,MAAM,CAAC,IAAI,CAAC;8BACE,GAAG;4CAAC;AAFR,eAAe;IAJ3B,OAAO,CAAC,WAAW,EAAE,wCAAwC,CAAC;IAC9D,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,6BAA6B,CAAC;IACnD,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,qCAAqC,CAAC;IAC5D,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,mDAAmD,CAAC;GAC/D,eAAe,CAc3B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CliCommand } from '@spinajs/cli';
|
|
2
|
+
import { Log } from '@spinajs/log-common';
|
|
3
|
+
interface WriteOptions {
|
|
4
|
+
content?: string;
|
|
5
|
+
fromFile?: string;
|
|
6
|
+
encoding: BufferEncoding;
|
|
7
|
+
}
|
|
8
|
+
export declare class FsWriteCommand extends CliCommand {
|
|
9
|
+
protected Log: Log;
|
|
10
|
+
execute(fsName: string, path: string, options: WriteOptions): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/cli/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA6B,MAAM,cAAc,CAAC;AACrE,OAAO,EAAU,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAMlD,UAAU,YAAY;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED,qBAMa,cAAe,SAAQ,UAAU;IAE5C,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAEN,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBzF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { CliCommand, Command, Argument, Option } from '@spinajs/cli';
|
|
11
|
+
import { Logger, Log } from '@spinajs/log-common';
|
|
12
|
+
import { readFileSync } from 'fs';
|
|
13
|
+
import { InvalidArgument } from '@spinajs/exceptions';
|
|
14
|
+
import { _write } from '../fp.js';
|
|
15
|
+
import { ensureProviders } from './fs.js';
|
|
16
|
+
let FsWriteCommand = class FsWriteCommand extends CliCommand {
|
|
17
|
+
async execute(fsName, path, options) {
|
|
18
|
+
await ensureProviders();
|
|
19
|
+
try {
|
|
20
|
+
if (options.fromFile) {
|
|
21
|
+
// binary-safe: read as buffer and write without re-encoding
|
|
22
|
+
const data = readFileSync(options.fromFile);
|
|
23
|
+
await _write(path, data, undefined, fsName);
|
|
24
|
+
}
|
|
25
|
+
else if (options.content !== undefined) {
|
|
26
|
+
await _write(path, options.content, options.encoding, fsName);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
throw new InvalidArgument('Provide content with --content or --from-file');
|
|
30
|
+
}
|
|
31
|
+
this.Log.success(`Wrote ${path} ( fs: ${fsName} )`);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
this.Log.error(`Cannot write ${path} on ${fsName}: ${err.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
__decorate([
|
|
39
|
+
Logger('fs'),
|
|
40
|
+
__metadata("design:type", Log)
|
|
41
|
+
], FsWriteCommand.prototype, "Log", void 0);
|
|
42
|
+
FsWriteCommand = __decorate([
|
|
43
|
+
Command('fs-write', 'Writes content to a file ( from inline text or a local file )'),
|
|
44
|
+
Argument('fs', true, 'Destination filesystem name'),
|
|
45
|
+
Argument('path', true, 'Path to file ( relative to selected fs base dir )'),
|
|
46
|
+
Option('-c, --content <content>', false, 'Inline text content to write'),
|
|
47
|
+
Option('-f, --from-file <fromFile>', false, 'Local file whose content will be written'),
|
|
48
|
+
Option('-e, --encoding <encoding>', false, 'Encoding used for inline content', 'utf-8')
|
|
49
|
+
], FsWriteCommand);
|
|
50
|
+
export { FsWriteCommand };
|
|
51
|
+
//# sourceMappingURL=write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/cli/write.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAA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;IADT,MAAM,CAAC,IAAI,CAAC;8BACE,GAAG;2CAAC;AAFR,cAAc;IAN1B,OAAO,CAAC,UAAU,EAAE,+DAA+D,CAAC;IACpF,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,6BAA6B,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,mDAAmD,CAAC;IAC3E,MAAM,CAAC,yBAAyB,EAAE,KAAK,EAAE,8BAA8B,CAAC;IACxE,MAAM,CAAC,4BAA4B,EAAE,KAAK,EAAE,0CAA0C,CAAC;IACvF,MAAM,CAAC,2BAA2B,EAAE,KAAK,EAAE,kCAAkC,EAAE,OAAO,CAAC;GAC3E,cAAc,CAuB1B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CliCommand } from '@spinajs/cli';
|
|
2
|
+
import { Log } from '@spinajs/log-common';
|
|
3
|
+
interface ZipOptions {
|
|
4
|
+
out?: string;
|
|
5
|
+
dstFs?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class FsZipCommand extends CliCommand {
|
|
8
|
+
protected Log: Log;
|
|
9
|
+
execute(fsName: string, paths: string, options: ZipOptions): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=zip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.d.ts","sourceRoot":"","sources":["../../../src/cli/zip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA6B,MAAM,cAAc,CAAC;AACrE,OAAO,EAAU,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAKlD,UAAU,UAAU;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAKa,YAAa,SAAQ,UAAU;IAE1C,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;IAEN,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAuBxF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { CliCommand, Command, Argument, Option } from '@spinajs/cli';
|
|
11
|
+
import { Logger, Log } from '@spinajs/log-common';
|
|
12
|
+
import { _fs } from '../fp.js';
|
|
13
|
+
import { IOFail } from '@spinajs/exceptions';
|
|
14
|
+
import { ensureProviders } from './fs.js';
|
|
15
|
+
let FsZipCommand = class FsZipCommand extends CliCommand {
|
|
16
|
+
async execute(fsName, paths, options) {
|
|
17
|
+
await ensureProviders();
|
|
18
|
+
try {
|
|
19
|
+
const provider = _fs(fsName)();
|
|
20
|
+
if (!provider) {
|
|
21
|
+
throw new IOFail(`Filesystem ${fsName} not found`);
|
|
22
|
+
}
|
|
23
|
+
const list = paths
|
|
24
|
+
.split(',')
|
|
25
|
+
.map((p) => p.trim())
|
|
26
|
+
.filter((p) => p.length > 0);
|
|
27
|
+
const dstFs = options.dstFs ? _fs(options.dstFs)() : undefined;
|
|
28
|
+
const result = await provider.zip(list, dstFs, options.out);
|
|
29
|
+
this.Log.success(`Zipped ${list.length} path(s) -> ${result.asFilePath()} ( fs: ${result.fs.Name} )`);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
this.Log.error(`Cannot zip on ${fsName}: ${err.message}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
__decorate([
|
|
37
|
+
Logger('fs'),
|
|
38
|
+
__metadata("design:type", Log)
|
|
39
|
+
], FsZipCommand.prototype, "Log", void 0);
|
|
40
|
+
FsZipCommand = __decorate([
|
|
41
|
+
Command('fs-zip', 'Compresses files / directories into a zip archive'),
|
|
42
|
+
Argument('fs', true, 'Source filesystem name'),
|
|
43
|
+
Argument('paths', true, 'Comma separated paths to compress ( relative to source fs )'),
|
|
44
|
+
Option('-o, --out <out>', false, 'Output zip file name ( relative to destination fs )'),
|
|
45
|
+
Option('-d, --dst-fs <dstFs>', false, 'Destination filesystem for the archive ( default fs-temp )')
|
|
46
|
+
], FsZipCommand);
|
|
47
|
+
export { FsZipCommand };
|
|
48
|
+
//# sourceMappingURL=zip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip.js","sourceRoot":"","sources":["../../../src/cli/zip.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAYnC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,UAAU;IAInC,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,KAAa,EAAE,OAAmB;QACrE,MAAM,eAAe,EAAE,CAAC;QAExB,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,E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sB,EAAE,KAAK,EAAE,4DAA4D,CAAC;GACvF,YAAY,CA2BxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../src/config/fs.ts"],"names":[],"mappings":"AAaA,QAAA,MAAM,EAAE;;;;;;CAOP,CAAC;AAEF,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { join, normalize, resolve } from 'path';
|
|
2
|
+
function dir(path) {
|
|
3
|
+
const inCommonJs = typeof module !== 'undefined';
|
|
4
|
+
return [
|
|
5
|
+
// installed as a dependency
|
|
6
|
+
resolve(normalize(join(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), 'node_modules', '@spinajs', 'fs', 'lib', inCommonJs ? 'cjs' : 'mjs', path))),
|
|
7
|
+
// one up if we run from app or build folder
|
|
8
|
+
resolve(normalize(join(process.env.WORKSPACE_ROOT_PATH ?? process.cwd(), '../', 'node_modules', '@spinajs', 'fs', 'lib', inCommonJs ? 'cjs' : 'mjs', path))),
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
const fs = {
|
|
12
|
+
system: {
|
|
13
|
+
dirs: {
|
|
14
|
+
// register fs cli commands so they are discovered by @spinajs/cli
|
|
15
|
+
cli: [...dir('cli')],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export default fs;
|
|
20
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../src/config/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IACjD,OAAO;QACL,4BAA4B;QAC5B,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QAErJ,4CAA4C;QAC5C,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;KAC7J,CAAC;AACJ,CAAC;AAED,MAAM,EAAE,GAAG;IACT,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,kEAAkE;YAClE,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;SACrB;KACF;CACF,CAAC;AAEF,eAAe,EAAE,CAAC"}
|
package/lib/mjs/file-hasher.d.ts
CHANGED
|
@@ -1,11 +1,91 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
1
|
+
import crypto, { BinaryToTextEncoding } from 'crypto';
|
|
2
|
+
import { IOFail } from '@spinajs/exceptions';
|
|
2
3
|
import { FileHasher } from './interfaces.js';
|
|
4
|
+
/**
|
|
5
|
+
* Default {@link FileHasher} implementation backed by node's `crypto` module.
|
|
6
|
+
*
|
|
7
|
+
* The algorithm is fixed per instance and provided as the first constructor
|
|
8
|
+
* argument ( eg. `DI.resolve(FileHasher, ['md5'])` ). When no algorithm is
|
|
9
|
+
* given it falls back to the value configured under `fs.hasher.defaultAlgorithm`,
|
|
10
|
+
* and finally to {@link DEFAULT_ALGORITHM} ( sha256 ).
|
|
11
|
+
*
|
|
12
|
+
* Instances are cached per algorithm via {@link PerInstanceCheck} /
|
|
13
|
+
* {@link __checkInstance__}, so resolving the same algorithm twice reuses the
|
|
14
|
+
* same hasher while different algorithms get distinct instances.
|
|
15
|
+
*/
|
|
3
16
|
export declare class DefaultFileHasher extends FileHasher {
|
|
4
|
-
|
|
17
|
+
Algorithm?: string | undefined;
|
|
5
18
|
HashOptions?: crypto.HashOptions | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Default algorithm read from configuration ( `fs.hasher.defaultAlgorithm` ),
|
|
21
|
+
* falling back to {@link DEFAULT_ALGORITHM} when the key is not set.
|
|
22
|
+
*
|
|
23
|
+
* Exposed as a lazily evaluated config property so both the constructor and
|
|
24
|
+
* {@link __checkInstance__} resolve the default the same way.
|
|
25
|
+
*/
|
|
26
|
+
protected ConfiguredAlgorithm: string;
|
|
27
|
+
/**
|
|
28
|
+
* Per-instance cache predicate used by {@link PerInstanceCheck}.
|
|
29
|
+
*
|
|
30
|
+
* Returns `true` when this instance was created for the algorithm requested in
|
|
31
|
+
* `creationOptions`. The requested algorithm is resolved exactly like the
|
|
32
|
+
* constructor does ( explicit arg, else the configured default ), so cached
|
|
33
|
+
* instances match reliably.
|
|
34
|
+
*
|
|
35
|
+
* @param creationOptions constructor arguments the container is resolving with
|
|
36
|
+
*/
|
|
6
37
|
__checkInstance__(creationOptions: any): boolean;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
38
|
+
/**
|
|
39
|
+
* @param Algorithm hash algorithm to use ( eg. `sha256`, `md5` ). When omitted,
|
|
40
|
+
* the configured default ( `fs.hasher.defaultAlgorithm` ) or
|
|
41
|
+
* sha256 is used.
|
|
42
|
+
* @param HashOptions optional node `crypto` hash options ( eg. `outputLength`
|
|
43
|
+
* for XOF algorithms such as shake256 )
|
|
44
|
+
*/
|
|
45
|
+
constructor(Algorithm?: string | undefined, HashOptions?: crypto.HashOptions | undefined);
|
|
46
|
+
/**
|
|
47
|
+
* Creates a `crypto.Hash` for the configured algorithm.
|
|
48
|
+
*
|
|
49
|
+
* The algorithm is validated against the platform's supported hashes first so
|
|
50
|
+
* an unsupported/typo'd algorithm produces a clear {@link IOFail} instead of a
|
|
51
|
+
* cryptic native crypto error.
|
|
52
|
+
*
|
|
53
|
+
* @throws {IOFail} when the configured algorithm is not supported
|
|
54
|
+
*/
|
|
55
|
+
protected createHasher(): crypto.Hash;
|
|
56
|
+
/**
|
|
57
|
+
* Hashes the content of a file by streaming it through the hash.
|
|
58
|
+
*
|
|
59
|
+
* @param pathToFile absolute path to the file to hash
|
|
60
|
+
* @param encoding digest output encoding ( default `hex` )
|
|
61
|
+
* @returns the digest string in the requested encoding
|
|
62
|
+
* @throws {IOFail} when the file does not exist, the algorithm is unsupported,
|
|
63
|
+
* or the file cannot be read
|
|
64
|
+
*/
|
|
65
|
+
hash(pathToFile: string, encoding?: BinaryToTextEncoding): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Consumes a readable stream through a fresh hasher and resolves with the
|
|
68
|
+
* digest. Stream errors are wrapped by `wrapError` so file and raw-stream
|
|
69
|
+
* callers surface their own context.
|
|
70
|
+
*/
|
|
71
|
+
protected digestStream(stream: NodeJS.ReadableStream, encoding: BinaryToTextEncoding, wrapError: (err: Error) => IOFail): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Hashes raw in-memory data.
|
|
74
|
+
*
|
|
75
|
+
* @param data string or binary data to hash
|
|
76
|
+
* @param encoding digest output encoding ( default `hex` )
|
|
77
|
+
* @returns the digest string in the requested encoding
|
|
78
|
+
* @throws {IOFail} when the configured algorithm is unsupported
|
|
79
|
+
*/
|
|
80
|
+
hashData(data: string | Uint8Array, encoding?: BinaryToTextEncoding): Promise<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Hashes the content of a readable stream by consuming it to the end.
|
|
83
|
+
*
|
|
84
|
+
* @param stream readable stream to consume
|
|
85
|
+
* @param encoding digest output encoding ( default `hex` )
|
|
86
|
+
* @returns the digest string in the requested encoding
|
|
87
|
+
* @throws {IOFail} when the configured algorithm is unsupported or the stream errors
|
|
88
|
+
*/
|
|
89
|
+
hashStream(stream: NodeJS.ReadableStream, encoding?: BinaryToTextEncoding): Promise<string>;
|
|
10
90
|
}
|
|
11
91
|
//# sourceMappingURL=file-hasher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-hasher.d.ts","sourceRoot":"","sources":["../../src/file-hasher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-hasher.d.ts","sourceRoot":"","sources":["../../src/file-hasher.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,EAAE,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAEtD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAO7C;;;;;;;;;;;GAWG;AACH,qBAEa,iBAAkB,SAAQ,UAAU;IAmC5B,SAAS,CAAC,EAAE,MAAM;IAAS,WAAW,CAAC,EAAE,MAAM,CAAC,WAAW;IAlC9E;;;;;;OAMG;IAEH,SAAS,CAAC,mBAAmB,EAAG,MAAM,CAAC;IAEvC;;;;;;;;;OASG;IAEI,iBAAiB,CAAC,eAAe,EAAE,GAAG,GAAG,OAAO;IAMvD;;;;;;OAMG;gBACgB,SAAS,CAAC,EAAE,MAAM,YAAA,EAAS,WAAW,CAAC,EAAE,MAAM,CAAC,WAAW,YAAA;IAM9E;;;;;;;;OAQG;IACH,SAAS,CAAC,YAAY,IAAI,MAAM,CAAC,IAAI;IAUrC;;;;;;;;OAQG;IACU,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,GAAE,oBAA4B,GAAG,OAAO,CAAC,MAAM,CAAC;IAY9F;;;;OAIG;IACH,SAAS,CAAC,YAAY,CACpB,MAAM,EAAE,MAAM,CAAC,cAAc,EAC7B,QAAQ,EAAE,oBAAoB,EAC9B,SAAS,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,MAAM,GAChC,OAAO,CAAC,MAAM,CAAC;IAWlB;;;;;;;OAOG;IACU,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,QAAQ,GAAE,oBAA4B,GAAG,OAAO,CAAC,MAAM,CAAC;IAMzG;;;;;;;OAOG;IACU,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,EAAE,QAAQ,GAAE,oBAA4B,GAAG,OAAO,CAAC,MAAM,CAAC;CAGhH"}
|
package/lib/mjs/file-hasher.js
CHANGED
|
@@ -8,39 +8,131 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Injectable, PerInstanceCheck } from '@spinajs/di';
|
|
11
|
+
import { Config } from '@spinajs/configuration';
|
|
11
12
|
import crypto from 'crypto';
|
|
12
13
|
import fs from 'node:fs';
|
|
13
14
|
import { IOFail } from '@spinajs/exceptions';
|
|
14
15
|
import { FileHasher } from './interfaces.js';
|
|
16
|
+
/**
|
|
17
|
+
* Hard fallback algorithm used when nothing is provided and no config default is set.
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULT_ALGORITHM = 'sha256';
|
|
20
|
+
/**
|
|
21
|
+
* Default {@link FileHasher} implementation backed by node's `crypto` module.
|
|
22
|
+
*
|
|
23
|
+
* The algorithm is fixed per instance and provided as the first constructor
|
|
24
|
+
* argument ( eg. `DI.resolve(FileHasher, ['md5'])` ). When no algorithm is
|
|
25
|
+
* given it falls back to the value configured under `fs.hasher.defaultAlgorithm`,
|
|
26
|
+
* and finally to {@link DEFAULT_ALGORITHM} ( sha256 ).
|
|
27
|
+
*
|
|
28
|
+
* Instances are cached per algorithm via {@link PerInstanceCheck} /
|
|
29
|
+
* {@link __checkInstance__}, so resolving the same algorithm twice reuses the
|
|
30
|
+
* same hasher while different algorithms get distinct instances.
|
|
31
|
+
*/
|
|
15
32
|
let DefaultFileHasher = class DefaultFileHasher extends FileHasher {
|
|
33
|
+
/**
|
|
34
|
+
* Per-instance cache predicate used by {@link PerInstanceCheck}.
|
|
35
|
+
*
|
|
36
|
+
* Returns `true` when this instance was created for the algorithm requested in
|
|
37
|
+
* `creationOptions`. The requested algorithm is resolved exactly like the
|
|
38
|
+
* constructor does ( explicit arg, else the configured default ), so cached
|
|
39
|
+
* instances match reliably.
|
|
40
|
+
*
|
|
41
|
+
* @param creationOptions constructor arguments the container is resolving with
|
|
42
|
+
*/
|
|
16
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
44
|
__checkInstance__(creationOptions) {
|
|
18
45
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
19
|
-
const requestedAlgo = creationOptions?.[0]
|
|
20
|
-
return this.
|
|
46
|
+
const requestedAlgo = creationOptions?.[0] ?? this.ConfiguredAlgorithm;
|
|
47
|
+
return this.Algorithm === requestedAlgo;
|
|
21
48
|
}
|
|
22
|
-
|
|
49
|
+
/**
|
|
50
|
+
* @param Algorithm hash algorithm to use ( eg. `sha256`, `md5` ). When omitted,
|
|
51
|
+
* the configured default ( `fs.hasher.defaultAlgorithm` ) or
|
|
52
|
+
* sha256 is used.
|
|
53
|
+
* @param HashOptions optional node `crypto` hash options ( eg. `outputLength`
|
|
54
|
+
* for XOF algorithms such as shake256 )
|
|
55
|
+
*/
|
|
56
|
+
constructor(Algorithm, HashOptions) {
|
|
23
57
|
super();
|
|
24
|
-
this.
|
|
58
|
+
this.Algorithm = Algorithm;
|
|
25
59
|
this.HashOptions = HashOptions;
|
|
26
|
-
this.
|
|
60
|
+
this.Algorithm = this.Algorithm || this.ConfiguredAlgorithm;
|
|
27
61
|
}
|
|
28
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Creates a `crypto.Hash` for the configured algorithm.
|
|
64
|
+
*
|
|
65
|
+
* The algorithm is validated against the platform's supported hashes first so
|
|
66
|
+
* an unsupported/typo'd algorithm produces a clear {@link IOFail} instead of a
|
|
67
|
+
* cryptic native crypto error.
|
|
68
|
+
*
|
|
69
|
+
* @throws {IOFail} when the configured algorithm is not supported
|
|
70
|
+
*/
|
|
71
|
+
createHasher() {
|
|
72
|
+
const algo = this.Algorithm;
|
|
73
|
+
if (!crypto.getHashes().includes(algo)) {
|
|
74
|
+
throw new IOFail(`Unsupported hash algorithm '${algo}'. Use one of: ${crypto.getHashes().join(', ')}`);
|
|
75
|
+
}
|
|
76
|
+
return crypto.createHash(algo, this.HashOptions);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Hashes the content of a file by streaming it through the hash.
|
|
80
|
+
*
|
|
81
|
+
* @param pathToFile absolute path to the file to hash
|
|
82
|
+
* @param encoding digest output encoding ( default `hex` )
|
|
83
|
+
* @returns the digest string in the requested encoding
|
|
84
|
+
* @throws {IOFail} when the file does not exist, the algorithm is unsupported,
|
|
85
|
+
* or the file cannot be read
|
|
86
|
+
*/
|
|
87
|
+
async hash(pathToFile, encoding = 'hex') {
|
|
29
88
|
if (!fs.existsSync(pathToFile)) {
|
|
30
89
|
throw new IOFail(`File ${pathToFile} not exists`);
|
|
31
90
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
91
|
+
return this.digestStream(fs.createReadStream(pathToFile), encoding, (err) => new IOFail(`Cannot read file ${pathToFile} for hashing`, err));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Consumes a readable stream through a fresh hasher and resolves with the
|
|
95
|
+
* digest. Stream errors are wrapped by `wrapError` so file and raw-stream
|
|
96
|
+
* callers surface their own context.
|
|
97
|
+
*/
|
|
98
|
+
digestStream(stream, encoding, wrapError) {
|
|
99
|
+
const hasher = this.createHasher();
|
|
36
100
|
return new Promise((resolve, reject) => {
|
|
37
|
-
|
|
38
|
-
.on('data', (data) =>
|
|
39
|
-
.on('end', () => resolve(
|
|
40
|
-
.on('error', (err) => reject(err));
|
|
101
|
+
stream
|
|
102
|
+
.on('data', (data) => hasher.update(data))
|
|
103
|
+
.on('end', () => resolve(hasher.digest(encoding)))
|
|
104
|
+
.on('error', (err) => reject(wrapError(err)));
|
|
41
105
|
});
|
|
42
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Hashes raw in-memory data.
|
|
109
|
+
*
|
|
110
|
+
* @param data string or binary data to hash
|
|
111
|
+
* @param encoding digest output encoding ( default `hex` )
|
|
112
|
+
* @returns the digest string in the requested encoding
|
|
113
|
+
* @throws {IOFail} when the configured algorithm is unsupported
|
|
114
|
+
*/
|
|
115
|
+
async hashData(data, encoding = 'hex') {
|
|
116
|
+
const hasher = this.createHasher();
|
|
117
|
+
hasher.update(data);
|
|
118
|
+
return hasher.digest(encoding);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Hashes the content of a readable stream by consuming it to the end.
|
|
122
|
+
*
|
|
123
|
+
* @param stream readable stream to consume
|
|
124
|
+
* @param encoding digest output encoding ( default `hex` )
|
|
125
|
+
* @returns the digest string in the requested encoding
|
|
126
|
+
* @throws {IOFail} when the configured algorithm is unsupported or the stream errors
|
|
127
|
+
*/
|
|
128
|
+
async hashStream(stream, encoding = 'hex') {
|
|
129
|
+
return this.digestStream(stream, encoding, (err) => new IOFail(`Error while hashing stream`, err));
|
|
130
|
+
}
|
|
43
131
|
};
|
|
132
|
+
__decorate([
|
|
133
|
+
Config('fs.hasher.defaultAlgorithm', { defaultValue: DEFAULT_ALGORITHM }),
|
|
134
|
+
__metadata("design:type", String)
|
|
135
|
+
], DefaultFileHasher.prototype, "ConfiguredAlgorithm", void 0);
|
|
44
136
|
DefaultFileHasher = __decorate([
|
|
45
137
|
Injectable(FileHasher),
|
|
46
138
|
PerInstanceCheck(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-hasher.js","sourceRoot":"","sources":["../../src/file-hasher.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,MAAM,MAAM,QAAQ,CAA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