gyomu 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 (77) hide show
  1. package/lib/archive/abstract.d.ts +7 -0
  2. package/lib/archive/abstract.js +30 -0
  3. package/lib/archive/gz.d.ts +16 -0
  4. package/lib/archive/gz.js +66 -0
  5. package/lib/archive/index.d.ts +3 -0
  6. package/lib/archive/index.js +19 -0
  7. package/lib/archive/tar.d.ts +17 -0
  8. package/lib/archive/tar.js +165 -0
  9. package/lib/archive/zip.d.ts +28 -0
  10. package/lib/archive/zip.js +254 -0
  11. package/lib/base64.d.ts +6 -0
  12. package/lib/base64.js +24 -0
  13. package/lib/buffer.d.ts +4 -0
  14. package/lib/buffer.js +23 -0
  15. package/lib/configurator.d.ts +16 -0
  16. package/lib/configurator.js +53 -0
  17. package/lib/dateOperation.d.ts +3 -0
  18. package/lib/dateOperation.js +23 -0
  19. package/lib/dbsingleton.d.ts +11 -0
  20. package/lib/dbsingleton.js +13 -0
  21. package/lib/dbutil.d.ts +3 -0
  22. package/lib/dbutil.js +44 -0
  23. package/lib/dictionary.d.ts +8 -0
  24. package/lib/dictionary.js +55 -0
  25. package/lib/encryption.d.ts +17 -0
  26. package/lib/encryption.js +202 -0
  27. package/lib/errors.d.ts +31 -0
  28. package/lib/errors.js +64 -0
  29. package/lib/excel.d.ts +1 -0
  30. package/lib/excel.js +34 -0
  31. package/lib/fileModel.d.ts +96 -0
  32. package/lib/fileModel.js +170 -0
  33. package/lib/fileOperation.d.ts +11 -0
  34. package/lib/fileOperation.js +275 -0
  35. package/lib/holidays.d.ts +20 -0
  36. package/lib/holidays.js +200 -0
  37. package/lib/index.d.ts +15 -0
  38. package/lib/index.js +31 -0
  39. package/lib/milestone.d.ts +19 -0
  40. package/lib/milestone.js +169 -0
  41. package/lib/net/_ftp.d.ts +0 -0
  42. package/lib/net/_ftp.js +228 -0
  43. package/lib/net/ftp.d.ts +19 -0
  44. package/lib/net/ftp.js +160 -0
  45. package/lib/net/remoteConnection.d.ts +11 -0
  46. package/lib/net/remoteConnection.js +26 -0
  47. package/lib/net/sftp.d.ts +19 -0
  48. package/lib/net/sftp.js +155 -0
  49. package/lib/numberOperation.d.ts +3 -0
  50. package/lib/numberOperation.js +24 -0
  51. package/lib/parameter.d.ts +14 -0
  52. package/lib/parameter.js +291 -0
  53. package/lib/result.d.ts +23 -0
  54. package/lib/result.js +47 -0
  55. package/lib/timer.d.ts +11 -0
  56. package/lib/timer.js +62 -0
  57. package/lib/user.d.ts +11 -0
  58. package/lib/user.js +23 -0
  59. package/lib/variable.d.ts +11 -0
  60. package/lib/variable.js +280 -0
  61. package/lib/web/attribute.d.ts +6 -0
  62. package/lib/web/attribute.js +29 -0
  63. package/lib/web/element.d.ts +24 -0
  64. package/lib/web/element.js +119 -0
  65. package/lib/web/index.d.ts +7 -0
  66. package/lib/web/index.js +19 -0
  67. package/lib/web/page.d.ts +22 -0
  68. package/lib/web/page.js +102 -0
  69. package/lib/web/table.d.ts +15 -0
  70. package/lib/web/table.js +110 -0
  71. package/lib/web/tableColumn.d.ts +10 -0
  72. package/lib/web/tableColumn.js +21 -0
  73. package/lib/web/tableRow.d.ts +10 -0
  74. package/lib/web/tableRow.js +80 -0
  75. package/lib/web/util.d.ts +12 -0
  76. package/lib/web/util.js +22 -0
  77. package/package.json +63 -0
@@ -0,0 +1,7 @@
1
+ export declare abstract class AbstractBaseArchive {
2
+ readonly archiveFileName: string;
3
+ constructor(tarFilename: string);
4
+ protected __massageEntryPath(fileName: string): string;
5
+ protected __createDirectoryFromFileNameIfNotExist(destinationFilename: string): void;
6
+ protected __createDirectoryIfNotExist(destinationPath: string): void;
7
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AbstractBaseArchive = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ class AbstractBaseArchive {
10
+ constructor(tarFilename) {
11
+ this.archiveFileName = tarFilename;
12
+ }
13
+ __massageEntryPath(fileName) {
14
+ return fileName.replace(/\\/g, '/');
15
+ }
16
+ __createDirectoryFromFileNameIfNotExist(destinationFilename) {
17
+ let directoryName = path_1.default.dirname(destinationFilename);
18
+ if (destinationFilename.endsWith(path_1.default.sep))
19
+ directoryName = destinationFilename;
20
+ return this.__createDirectoryIfNotExist(directoryName);
21
+ }
22
+ __createDirectoryIfNotExist(destinationPath) {
23
+ let directoryName = destinationPath;
24
+ if (!fs_1.default.existsSync(directoryName)) {
25
+ //console.log(directoryName + ' to be created');
26
+ fs_1.default.mkdirSync(directoryName);
27
+ }
28
+ }
29
+ }
30
+ exports.AbstractBaseArchive = AbstractBaseArchive;
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import { ArchiveError } from '../errors';
3
+ import { PromiseResult } from '../result';
4
+ import { AbstractBaseArchive } from './abstract';
5
+ import zlib from 'zlib';
6
+ /**
7
+ * @remarks
8
+ * This class (extract side) doesn't support stream based retrieval yet
9
+ */
10
+ export declare class GzipArchive extends AbstractBaseArchive {
11
+ static create(gzipFilename: string, sourceFilename: string): PromiseResult<boolean, ArchiveError>;
12
+ static extract(gzipFilename: string, destinationFilename: string): PromiseResult<boolean, ArchiveError>;
13
+ static getGzipTransform(): zlib.Gzip;
14
+ static getGunzipTransform(): zlib.Gunzip;
15
+ static extractStream(gzipFilename: string): zlib.Gunzip;
16
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GzipArchive = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const errors_1 = require("../errors");
18
+ const result_1 = require("../result");
19
+ const abstract_1 = require("./abstract");
20
+ const zlib_1 = __importDefault(require("zlib"));
21
+ /**
22
+ * @remarks
23
+ * This class (extract side) doesn't support stream based retrieval yet
24
+ */
25
+ class GzipArchive extends abstract_1.AbstractBaseArchive {
26
+ static create(gzipFilename, sourceFilename) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return new Promise((resolve, reject) => {
29
+ fs_1.default.createReadStream(sourceFilename)
30
+ .pipe(zlib_1.default.createGzip())
31
+ .pipe(fs_1.default.createWriteStream(gzipFilename))
32
+ .on('error', (err) => {
33
+ resolve(new result_1.Failure(new errors_1.ArchiveError('Error on gzip compression', err)));
34
+ })
35
+ .on('finish', () => {
36
+ resolve((0, result_1.success)(true));
37
+ });
38
+ });
39
+ });
40
+ }
41
+ static extract(gzipFilename, destinationFilename) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ return new Promise((resolve, reject) => {
44
+ fs_1.default.createReadStream(gzipFilename)
45
+ .pipe(zlib_1.default.createGunzip())
46
+ .pipe(fs_1.default.createWriteStream(destinationFilename))
47
+ .on('error', (err) => {
48
+ resolve(new result_1.Failure(new errors_1.ArchiveError('Error on gzip uncompression', err)));
49
+ })
50
+ .on('finish', () => {
51
+ resolve((0, result_1.success)(true));
52
+ });
53
+ });
54
+ });
55
+ }
56
+ static getGzipTransform() {
57
+ return zlib_1.default.createGzip();
58
+ }
59
+ static getGunzipTransform() {
60
+ return zlib_1.default.createGunzip();
61
+ }
62
+ static extractStream(gzipFilename) {
63
+ return fs_1.default.createReadStream(gzipFilename).pipe(zlib_1.default.createGunzip());
64
+ }
65
+ }
66
+ exports.GzipArchive = GzipArchive;
@@ -0,0 +1,3 @@
1
+ export * from './gz';
2
+ export * from './tar';
3
+ export * from './zip';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./gz"), exports);
18
+ __exportStar(require("./tar"), exports);
19
+ __exportStar(require("./zip"), exports);
@@ -0,0 +1,17 @@
1
+ import { FileTransportInfo } from '../fileModel';
2
+ import { ArchiveError } from '../errors';
3
+ import { PromiseResult } from '../result';
4
+ import { AbstractBaseArchive } from './abstract';
5
+ /**
6
+ * @remarks
7
+ * This class (extract side) doesn't support stream based retrieval yet
8
+ */
9
+ export declare class TarArchive extends AbstractBaseArchive {
10
+ static create(tarFileName: string, transferInformation: FileTransportInfo, needGZipCompression?: boolean): PromiseResult<boolean, ArchiveError>;
11
+ constructor(tarFilename: string);
12
+ fileExists(fileName: string): PromiseResult<boolean, ArchiveError>;
13
+ extractSingileFile(sourceEntryFullName: string, destinationFolderName: string): PromiseResult<boolean, ArchiveError>;
14
+ extractDirectory(sourceDirectory: string, destinationDirectory: string): PromiseResult<boolean, ArchiveError>;
15
+ extractAll(destinationDirectory: string): PromiseResult<boolean, ArchiveError>;
16
+ extract(transferInformation: FileTransportInfo): PromiseResult<boolean, ArchiveError>;
17
+ }
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TarArchive = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const errors_1 = require("../errors");
18
+ const result_1 = require("../result");
19
+ // import tarStream from 'tar-stream';
20
+ // import tar from 'tar-fs';
21
+ const tar_1 = __importDefault(require("tar"));
22
+ const abstract_1 = require("./abstract");
23
+ /**
24
+ * @remarks
25
+ * This class (extract side) doesn't support stream based retrieval yet
26
+ */
27
+ class TarArchive extends abstract_1.AbstractBaseArchive {
28
+ static create(tarFileName, transferInformation, needGZipCompression = false) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ let currentDirectory = path_1.default.dirname(transferInformation.sourceFullNameWithBasePath);
31
+ let targetPathForTar = transferInformation.sourceFullNameWithBasePath.substring(currentDirectory.length + path_1.default.sep.length);
32
+ // console.log('current', currentDirectory);
33
+ // console.log('target', targetPathForTar);
34
+ if (!transferInformation.isSourceDirectory) {
35
+ return (0, result_1.fail)('Single File is not supported', errors_1.ArchiveError);
36
+ }
37
+ let tarOptions;
38
+ tarOptions = {
39
+ file: tarFileName,
40
+ cwd: transferInformation.sourceFullNameWithBasePath,
41
+ };
42
+ if (needGZipCompression) {
43
+ tarOptions = {
44
+ file: tarFileName,
45
+ cwd: transferInformation.sourceFullNameWithBasePath,
46
+ gzip: true,
47
+ };
48
+ }
49
+ return new Promise((resolve, reject) => {
50
+ let result;
51
+ if (!needGZipCompression) {
52
+ result = tar_1.default.create({
53
+ file: tarFileName,
54
+ cwd: transferInformation.sourceFullNameWithBasePath,
55
+ }, ['']);
56
+ }
57
+ else {
58
+ result = tar_1.default.create({
59
+ file: tarFileName,
60
+ cwd: transferInformation.sourceFullNameWithBasePath,
61
+ gzip: true,
62
+ }, ['']);
63
+ }
64
+ result
65
+ .then(() => {
66
+ return resolve((0, result_1.success)(true));
67
+ })
68
+ .catch((err) => {
69
+ return resolve((0, result_1.fail)('Fail to Tar archive', errors_1.ArchiveError));
70
+ });
71
+ });
72
+ });
73
+ }
74
+ constructor(tarFilename) {
75
+ super(tarFilename);
76
+ }
77
+ fileExists(fileName) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ fileName = this.__massageEntryPath(fileName);
80
+ let isExist = false;
81
+ const extract = yield tar_1.default.list({
82
+ file: this.archiveFileName,
83
+ onentry: (entry) => {
84
+ if (entry.header.path === fileName)
85
+ isExist = true;
86
+ },
87
+ });
88
+ return (0, result_1.success)(isExist);
89
+ });
90
+ }
91
+ extractSingileFile(sourceEntryFullName, destinationFolderName) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const targetEntryName = this.__massageEntryPath(sourceEntryFullName);
94
+ const numPathElementToSkip = (targetEntryName.match(/\//g) || []).length;
95
+ this.__createDirectoryIfNotExist(destinationFolderName);
96
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
97
+ yield tar_1.default
98
+ .extract({
99
+ cwd: destinationFolderName,
100
+ file: this.archiveFileName,
101
+ filter: (path, stat) => {
102
+ return path === targetEntryName;
103
+ },
104
+ strip: numPathElementToSkip,
105
+ })
106
+ .then(() => {
107
+ return resolve((0, result_1.success)(true));
108
+ })
109
+ .catch((reason) => {
110
+ return resolve(new result_1.Failure(new errors_1.ArchiveError(`Fail to untar ${this.archiveFileName} -> ${targetEntryName}`, reason)));
111
+ });
112
+ }));
113
+ });
114
+ }
115
+ extractDirectory(sourceDirectory, destinationDirectory) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ const targetEntryName = this.__massageEntryPath(sourceDirectory);
118
+ const numPathElementToSkip = !sourceDirectory
119
+ ? 0
120
+ : (targetEntryName.match(/\//g) || []).length + 1;
121
+ //let directoryName = path.dirname(destinationDirectory);
122
+ this.__createDirectoryIfNotExist(destinationDirectory);
123
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
124
+ yield tar_1.default
125
+ .extract({
126
+ cwd: destinationDirectory,
127
+ file: this.archiveFileName,
128
+ filter: (path, stat) => {
129
+ return !targetEntryName || path.startsWith(targetEntryName);
130
+ },
131
+ strip: numPathElementToSkip,
132
+ })
133
+ .then(() => {
134
+ resolve((0, result_1.success)(true));
135
+ })
136
+ .catch((reason) => {
137
+ resolve(new result_1.Failure(new errors_1.ArchiveError(`Fail to untar ${this.archiveFileName} -> ${targetEntryName}`, reason)));
138
+ });
139
+ }));
140
+ });
141
+ }
142
+ extractAll(destinationDirectory) {
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ return this.extractDirectory('', destinationDirectory);
145
+ });
146
+ }
147
+ extract(transferInformation) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ //console.log('directory', directory);
150
+ const targetEntryName = this.__massageEntryPath(transferInformation.sourceFullName);
151
+ if (transferInformation.sourceFileName !==
152
+ transferInformation.destinationFileName)
153
+ return (0, result_1.fail)('Destination filename must be same as original filename', errors_1.ArchiveError);
154
+ //console.log('targetEntryName:', targetEntryName, ':');
155
+ //const directory = await unzipper.Open.file(this.zipFilename);
156
+ if (!transferInformation.isSourceDirectory) {
157
+ return yield this.extractSingileFile(transferInformation.sourceFullName, transferInformation.destinationPath);
158
+ }
159
+ else {
160
+ return yield this.extractDirectory(transferInformation.sourceFullName, transferInformation.destinationFullName);
161
+ }
162
+ });
163
+ }
164
+ }
165
+ exports.TarArchive = TarArchive;
@@ -0,0 +1,28 @@
1
+ import { FileTransportInfo } from '../fileModel';
2
+ import { ArchiveError } from '../errors';
3
+ import { PromiseResult } from '../result';
4
+ import { AbstractBaseArchive } from './abstract';
5
+ /**
6
+ * @remarks
7
+ * This class (extract side) doesn't support stream based retrieval yet
8
+ * This class doesn't support AES decryption yet
9
+ */
10
+ export declare class ZipArchive extends AbstractBaseArchive {
11
+ #private;
12
+ static _initialize(): void;
13
+ static create(zipFileName: string, transferInformationList: FileTransportInfo[], password?: string): PromiseResult<boolean, ArchiveError>;
14
+ readonly password: string;
15
+ readonly isAesEncrypted: boolean;
16
+ readonly encoding: string;
17
+ constructor({ zipFilename, password, encoding, isAesEncrypted, }: {
18
+ zipFilename: string;
19
+ password?: string;
20
+ encoding?: string;
21
+ isAesEncrypted?: boolean;
22
+ });
23
+ fileExists(fileName: string): PromiseResult<boolean, ArchiveError>;
24
+ extractSingileFile(sourceEntryFullName: string, destinationFullName: string): PromiseResult<boolean, ArchiveError>;
25
+ extractDirectory(sourceDirectory: string, destinationDirectory: string): PromiseResult<boolean, ArchiveError>;
26
+ extractAll(destinationDirectory: string): PromiseResult<boolean, ArchiveError>;
27
+ extract(transferInformation: FileTransportInfo): PromiseResult<boolean, ArchiveError>;
28
+ }
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ var _ZipArchive_instances, _ZipArchive_unicode, _ZipArchive_massageFileEntryFullPath;
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.ZipArchive = void 0;
22
+ const fs_1 = __importDefault(require("fs"));
23
+ const path_1 = __importDefault(require("path"));
24
+ const errors_1 = require("../errors");
25
+ const result_1 = require("../result");
26
+ const archiver_1 = __importDefault(require("archiver"));
27
+ const unzipper_1 = __importDefault(require("unzipper"));
28
+ const iconv_lite_1 = __importDefault(require("iconv-lite"));
29
+ const abstract_1 = require("./abstract");
30
+ const fileOperation_1 = require("../fileOperation");
31
+ /**
32
+ * @remarks
33
+ * This class (extract side) doesn't support stream based retrieval yet
34
+ * This class doesn't support AES decryption yet
35
+ */
36
+ class ZipArchive extends abstract_1.AbstractBaseArchive {
37
+ constructor({ zipFilename, password = '', encoding = '', isAesEncrypted = false, }) {
38
+ super(zipFilename);
39
+ _ZipArchive_instances.add(this);
40
+ _ZipArchive_unicode.set(this, 0x800);
41
+ this.password = password;
42
+ this.isAesEncrypted = isAesEncrypted;
43
+ this.encoding = encoding;
44
+ }
45
+ static _initialize() {
46
+ archiver_1.default.registerFormat('zip-encrypted', require('archiver-zip-encrypted'));
47
+ }
48
+ static create(zipFileName, transferInformationList, password = '') {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const archive = password === ''
51
+ ? archiver_1.default.create('zip', { forceZip64: true })
52
+ : archiver_1.default.create('zip-encrypted', {
53
+ forceZip64: true,
54
+ encryptionMethod: 'zip20',
55
+ password,
56
+ });
57
+ //outputStream.on('close',()=>)
58
+ archive.on('warning', (err) => {
59
+ if (err.code === 'ENOENT') {
60
+ console.log(err.message);
61
+ }
62
+ else {
63
+ return new result_1.Failure(new errors_1.ArchiveError('Unknown Warning on Archive', err));
64
+ }
65
+ });
66
+ archive.on('error', (err) => {
67
+ return new result_1.Failure(new errors_1.ArchiveError('Unknown Error on Archive', err));
68
+ });
69
+ archive.on('close', () => {
70
+ //console.log('close');
71
+ });
72
+ archive.on('end', function () {
73
+ //console.log('Data has been drained');
74
+ });
75
+ archive.on('finish', function () {
76
+ //console.log('finish');
77
+ });
78
+ const outputStream = fs_1.default.createWriteStream(zipFileName);
79
+ archive.pipe(outputStream);
80
+ for (const transferInformation of transferInformationList) {
81
+ const sourcePath = transferInformation.sourceFullNameWithBasePath;
82
+ if (!fs_1.default.existsSync(sourcePath))
83
+ return (0, result_1.fail)(`File Not Found: ${sourcePath}`, errors_1.ArchiveError);
84
+ if (!transferInformation.isSourceDirectory) {
85
+ let destinationEntryName = transferInformation.destinationFullName.replace(path_1.default.sep, '/');
86
+ archive.file(sourcePath, { name: destinationEntryName });
87
+ }
88
+ else {
89
+ archive.directory(sourcePath, transferInformation.destinationPath
90
+ ? transferInformation.destinationPath
91
+ : false);
92
+ //this.#buildZipArchiveInternal(sourcePath, sourcePath, archive);
93
+ }
94
+ }
95
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
96
+ yield archive
97
+ .finalize()
98
+ .then(() => __awaiter(this, void 0, void 0, function* () {
99
+ if (!!password) {
100
+ yield fileOperation_1.FileOperation.waitTillExclusiveAccess(zipFileName, 1);
101
+ }
102
+ return resolve((0, result_1.success)(true));
103
+ }))
104
+ .catch((err) => {
105
+ return resolve(new result_1.Failure(new errors_1.ArchiveError('Fail to zip archive', err)));
106
+ });
107
+ // console.log('final');
108
+ return resolve((0, result_1.success)(true));
109
+ }));
110
+ });
111
+ }
112
+ fileExists(fileName) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ fileName = this.__massageEntryPath(fileName);
115
+ return new Promise((resolve, reject) => {
116
+ return unzipper_1.default.Open.file(this.archiveFileName)
117
+ .then((directory) => {
118
+ const targetFile = directory.files.find((f) => {
119
+ return (f.type === 'File' &&
120
+ __classPrivateFieldGet(this, _ZipArchive_instances, "m", _ZipArchive_massageFileEntryFullPath).call(this, f) === fileName);
121
+ });
122
+ return resolve((0, result_1.success)(!!targetFile));
123
+ })
124
+ .catch((err) => {
125
+ return resolve(new result_1.Failure(new errors_1.ArchiveError(`Fail to check file existence of ${this.archiveFileName}->${fileName}`, err)));
126
+ });
127
+ });
128
+ });
129
+ }
130
+ // #createDirectoryFromFileNameIfNotExist(destinationFilename: string) {
131
+ // let directoryName = path.dirname(destinationFilename);
132
+ // if (destinationFilename.endsWith(path.sep))
133
+ // directoryName = destinationFilename;
134
+ // return this.#createDirectoryIfNotExist(directoryName);
135
+ // }
136
+ // #createDirectoryIfNotExist(destinationPath: string) {
137
+ // let directoryName = destinationPath;
138
+ // if (!fs.existsSync(directoryName)) {
139
+ // console.log(directoryName + ' to be created');
140
+ // fs.mkdirSync(directoryName);
141
+ // }
142
+ // }
143
+ extractSingileFile(sourceEntryFullName, destinationFullName) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ const targetEntryName = this.__massageEntryPath(sourceEntryFullName);
146
+ return unzipper_1.default.Open.file(this.archiveFileName).then((directory) => {
147
+ const targetFile = directory.files.find((f) => {
148
+ return (f.type === 'File' &&
149
+ __classPrivateFieldGet(this, _ZipArchive_instances, "m", _ZipArchive_massageFileEntryFullPath).call(this, f) === targetEntryName);
150
+ });
151
+ if (!targetFile) {
152
+ console.log(`File not found :${targetEntryName}`);
153
+ return (0, result_1.fail)(`File not found :${targetEntryName}`, errors_1.ArchiveError);
154
+ }
155
+ this.__createDirectoryFromFileNameIfNotExist(destinationFullName);
156
+ return new Promise((resolve, reject) => {
157
+ targetFile
158
+ .stream(this.password)
159
+ .pipe(fs_1.default.createWriteStream(destinationFullName))
160
+ .on('error', (err) => {
161
+ return resolve(new result_1.Failure(new errors_1.ArchiveError(`Unknown Error on extract ${__classPrivateFieldGet(this, _ZipArchive_instances, "m", _ZipArchive_massageFileEntryFullPath).call(this, targetFile)}`, err)));
162
+ })
163
+ .on('finish', () => {
164
+ resolve((0, result_1.success)(true));
165
+ });
166
+ });
167
+ });
168
+ });
169
+ }
170
+ extractDirectory(sourceDirectory, destinationDirectory) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ const targetEntryName = this.__massageEntryPath(sourceDirectory);
173
+ const result = unzipper_1.default.Open.file(this.archiveFileName).then((directory) => __awaiter(this, void 0, void 0, function* () {
174
+ const targetFileList = directory.files.filter((f) => __classPrivateFieldGet(this, _ZipArchive_instances, "m", _ZipArchive_massageFileEntryFullPath).call(this, f).startsWith(targetEntryName));
175
+ if (!targetFileList || targetFileList.length === 0) {
176
+ return (0, result_1.fail)(`Folder not found : ${targetEntryName}`, errors_1.ArchiveError);
177
+ }
178
+ this.__createDirectoryIfNotExist(destinationDirectory);
179
+ targetFileList
180
+ .filter((file) => file.type === 'Directory')
181
+ .forEach((file) => {
182
+ const entryFullPath = __classPrivateFieldGet(this, _ZipArchive_instances, "m", _ZipArchive_massageFileEntryFullPath).call(this, file);
183
+ let destinationPath = path_1.default.join(destinationDirectory, entryFullPath
184
+ .substring(targetEntryName.length)
185
+ .replace('/', path_1.default.sep));
186
+ this.__createDirectoryFromFileNameIfNotExist(destinationPath);
187
+ });
188
+ const resultPromiseList = yield targetFileList
189
+ .filter((file) => file.type === 'File')
190
+ .map((file) => __awaiter(this, void 0, void 0, function* () {
191
+ const entryFullPath = __classPrivateFieldGet(this, _ZipArchive_instances, "m", _ZipArchive_massageFileEntryFullPath).call(this, file);
192
+ let destinationPath = path_1.default.join(destinationDirectory, entryFullPath
193
+ .substring(targetEntryName.length)
194
+ .replace('/', path_1.default.sep));
195
+ this.__createDirectoryFromFileNameIfNotExist(destinationPath);
196
+ return new Promise((resolve, reject) => {
197
+ file
198
+ .stream(this.password)
199
+ .pipe(fs_1.default.createWriteStream(destinationPath))
200
+ .on('error', (err) => {
201
+ reject({
202
+ err: err,
203
+ fileName: __classPrivateFieldGet(this, _ZipArchive_instances, "m", _ZipArchive_massageFileEntryFullPath).call(this, file),
204
+ });
205
+ })
206
+ .on('finish', resolve);
207
+ });
208
+ }));
209
+ const result = yield Promise.all(resultPromiseList)
210
+ .then((results) => {
211
+ //return new Promise<void>((resolve,reject)=>{resolve();})
212
+ return (0, result_1.success)(true);
213
+ })
214
+ .catch((reason) => {
215
+ return new result_1.Failure(new errors_1.ArchiveError(`Error on unarchive ${reason.fileName}`, reason.err));
216
+ });
217
+ return result;
218
+ }));
219
+ return result;
220
+ });
221
+ }
222
+ extractAll(destinationDirectory) {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ return this.extractDirectory('', destinationDirectory);
225
+ });
226
+ }
227
+ extract(
228
+ //zipFilename: string,
229
+ transferInformation) {
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ //console.log('directory', directory);
232
+ const targetEntryName = this.__massageEntryPath(transferInformation.sourceFullName);
233
+ //console.log('targetEntryName:', targetEntryName, ':');
234
+ //const directory = await unzipper.Open.file(this.zipFilename);
235
+ if (!transferInformation.isSourceDirectory) {
236
+ return yield this.extractSingileFile(transferInformation.sourceFullName, transferInformation.destinationFullName);
237
+ }
238
+ else {
239
+ return yield this.extractDirectory(transferInformation.sourceFullName, transferInformation.destinationFullName);
240
+ }
241
+ });
242
+ }
243
+ }
244
+ exports.ZipArchive = ZipArchive;
245
+ _ZipArchive_unicode = new WeakMap(), _ZipArchive_instances = new WeakSet(), _ZipArchive_massageFileEntryFullPath = function _ZipArchive_massageFileEntryFullPath(file) {
246
+ if (!this.encoding ||
247
+ (!!file.flags && (file.flags & __classPrivateFieldGet(this, _ZipArchive_unicode, "f")) !== 0)) {
248
+ return file.path;
249
+ }
250
+ const decoded = iconv_lite_1.default.decode(file.pathBuffer, this.encoding);
251
+ // console.log(decoded);
252
+ return decoded;
253
+ };
254
+ ZipArchive._initialize();
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ export declare type SupportEncoding = 'shiftjis' | 'utf8';
3
+ export declare const string2Base64String: (plainString: string) => string;
4
+ export declare const buffer2Base64String: (buffer: Buffer) => string;
5
+ export declare const base64String2String: (encodedString: string) => string;
6
+ export declare const base64String2Buffer: (encodedString: string) => Buffer;
package/lib/base64.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.base64String2Buffer = exports.base64String2String = exports.buffer2Base64String = exports.string2Base64String = void 0;
4
+ const string2Base64String = (plainString) => {
5
+ return (0, exports.buffer2Base64String)(Buffer.from(plainString));
6
+ };
7
+ exports.string2Base64String = string2Base64String;
8
+ const buffer2Base64String = (buffer) => {
9
+ return buffer.toString('base64');
10
+ };
11
+ exports.buffer2Base64String = buffer2Base64String;
12
+ const base64String2String = (encodedString) => {
13
+ return (0, exports.base64String2Buffer)(encodedString).toString();
14
+ };
15
+ exports.base64String2String = base64String2String;
16
+ const base64String2Buffer = (encodedString) => {
17
+ return Buffer.from(encodedString, 'base64');
18
+ };
19
+ exports.base64String2Buffer = base64String2Buffer;
20
+ // export const base64String2ArrayBuffer = (
21
+ // encodedString: string
22
+ // ): ArrayBuffer => {
23
+ // return base64String2Buffer(encodedString).buffer;
24
+ // };
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ export declare const stringToArrayBuffer: (source: string) => ArrayBuffer;
3
+ export declare const arrayBufferToString: (source: ArrayBuffer) => string;
4
+ export declare const bufferToArrayBuffer: (buffer: Buffer) => ArrayBuffer;