node-opcua-file-transfer 2.97.0 → 2.98.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.
@@ -1,66 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.writeOPCUAFile = void 0;
13
- const fs = require("node:fs");
14
- const node_stream_1 = require("node:stream");
15
- const promises_1 = require("node:stream/promises");
16
- const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
17
- const node_opcua_debug_1 = require("node-opcua-debug");
18
- const client_file_1 = require("./client_file");
19
- const read_max_byte_string_length_1 = require("./read_max_byte_string_length");
20
- const debugLog = (0, node_opcua_debug_1.make_debugLog)("FileType");
21
- // const errorLog = make_errorLog("FileType");
22
- // const warningLog = make_warningLog("FileType");
23
- const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("FileType");
24
- function getTransportMaxMessageSize(session) {
25
- return session.getTransportSettings ? session.getTransportSettings().maxMessageSize : 0;
26
- }
27
- function writeOPCUAFile(clientFile, filePath, { chunkSize }) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const maxMessageSize = getTransportMaxMessageSize(clientFile.session);
30
- chunkSize = chunkSize === undefined ? yield (0, read_max_byte_string_length_1.readMaxByteStringLength)(clientFile.session) : chunkSize;
31
- chunkSize = Math.min(chunkSize, node_opcua_binary_stream_1.BinaryStream.maxByteStringLength);
32
- if (maxMessageSize > 200) {
33
- chunkSize = Math.min(chunkSize, maxMessageSize - 1000);
34
- }
35
- console.log("chunkSize = ", chunkSize, maxMessageSize);
36
- if (!fs.existsSync(filePath)) {
37
- throw new Error(`File ${filePath} does not exist`);
38
- }
39
- const readStream = fs.createReadStream(filePath, { highWaterMark: chunkSize });
40
- yield clientFile.open(client_file_1.OpenFileMode.WriteEraseExisting);
41
- yield clientFile.setPosition(0);
42
- try {
43
- const outStream = new node_stream_1.Writable({
44
- write(chunk, encoding, callback) {
45
- doDebug && debugLog("writing chunk", chunk.length);
46
- clientFile
47
- .write(chunk)
48
- .then(() => callback())
49
- .catch((err) => callback(err));
50
- }
51
- });
52
- // note: pipeline requires NodeJS 15 or above
53
- yield (0, promises_1.pipeline)(readStream, outStream);
54
- }
55
- catch (e) {
56
- debugLog(e.message);
57
- throw e;
58
- }
59
- finally {
60
- doDebug && debugLog("closing the OPCUA File");
61
- yield clientFile.close();
62
- }
63
- });
64
- }
65
- exports.writeOPCUAFile = writeOPCUAFile;
66
- //# sourceMappingURL=write_file.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"write_file.js","sourceRoot":"","sources":["../../source/client/write_file.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8BAA8B;AAC9B,6CAAuC;AACvC,mDAAgD;AAGhD,uEAAwD;AAExD,uDAAiE;AAGjE,+CAA0D;AAC1D,+EAAwE;AAExE,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,UAAU,CAAC,CAAC;AAC3C,8CAA8C;AAC9C,kDAAkD;AAClD,MAAM,OAAO,GAAG,IAAA,iCAAc,EAAC,UAAU,CAAC,CAAC;AAE3C,SAAS,0BAA0B,CAAC,OAAsB;IACtD,OAAO,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5F,CAAC;AAED,SAAsB,cAAc,CAAC,UAAuB,EAAE,QAAgB,EAAE,EAAE,SAAS,EA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gBACvC,CAAC;aACJ,CAAC,CAAC;YACH,6CAA6C;YAC7C,MAAM,IAAA,mBAAQ,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;SACzC;QAAC,OAAO,CAAC,EAAE;YACR,QAAQ,CAAE,CAAW,CAAC,OAAO,CAAC,CAAC;YAC/B,MAAM,CAAC,CAAC;SACX;gBAAS;YACN,OAAO,IAAI,QAAQ,CAAC,wBAAwB,CAAC,CAAC;YAC9C,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;SAC5B;IACL,CAAC;CAAA;AAnCD,wCAmCC"}
@@ -1,19 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- import { Stats, PathLike, OpenMode, NoParamCallback, WriteFileOptions } from "fs";
5
- export interface ReadStreamOptions {
6
- }
7
- export interface AbstractFs {
8
- stat(path: PathLike, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => void): void;
9
- open(path: PathLike, flags: OpenMode, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
10
- write<TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, offset: number | undefined | null, length: number | undefined | null, position: number | undefined | null, callback: (err: NodeJS.ErrnoException | null, bytesWritten: number, buffer: TBuffer) => void): void;
11
- read<TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, offset: number, length: number, position: number | null, callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: TBuffer) => void): void;
12
- close(fd: number, callback: NoParamCallback): void;
13
- writeFile(path: PathLike | number, data: string | NodeJS.ArrayBufferView, options: WriteFileOptions, callback: NoParamCallback): void;
14
- readFile(path: PathLike | number, options: {
15
- encoding: BufferEncoding;
16
- flag?: string;
17
- } | string, callback: (err: NodeJS.ErrnoException | null, data: string) => void): void;
18
- existsSync(filename: string): boolean;
19
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=abstract_fs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"abstract_fs.js","sourceRoot":"","sources":["../../source/common/abstract_fs.ts"],"names":[],"mappings":""}
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * @module node-opcua-file-transfer
3
- */
4
- export * from "./client";
5
- export * from "./server/file_type_helpers";
6
- export * from "./common/abstract_fs";
package/dist/index.js DELETED
@@ -1,23 +0,0 @@
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
- /**
18
- * @module node-opcua-file-transfer
19
- */
20
- __exportStar(require("./client"), exports);
21
- __exportStar(require("./server/file_type_helpers"), exports);
22
- __exportStar(require("./common/abstract_fs"), exports);
23
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,2CAAyB;AACzB,6DAA2C;AAC3C,uDAAqC"}
@@ -1,39 +0,0 @@
1
- /**
2
- * @module node-opcua-file-transfer-server
3
- */
4
- export declare enum OpenFileModeMask {
5
- ReadBit = 1,
6
- WriteBit = 2,
7
- EraseExistingBit = 4,
8
- AppendBit = 8
9
- }
10
- export declare enum OpenFileMode {
11
- /**
12
- * Read bit 0 The file is opened for reading. If this bit is not
13
- * set the Read Method cannot be executed.
14
- */
15
- Read = 1,
16
- /**
17
- * Write bit 1 The file is opened for writing. If this bit is not
18
- * set the Write Method cannot be executed.
19
- *
20
- */
21
- Write = 2,
22
- ReadWrite = 3,
23
- /**
24
- *
25
- * WriteEraseExisting
26
- * EraseExisting 2 This bit can only be set if the file is opened for writing
27
- * (Write bit is set). The existing content of the file is
28
- * erased and an empty file is provided.
29
- */
30
- WriteEraseExisting = 6,
31
- ReadWriteEraseExisting = 7,
32
- /**
33
- * Append 3 When the Append bit is set the file is opened at end
34
- * of the file, otherwise at begin of the file.
35
- * The SetPosition Method can be used to change the position.
36
- */
37
- WriteAppend = 10,
38
- ReadWriteAppend = 11
39
- }
package/dist/open_mode.js DELETED
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenFileMode = exports.OpenFileModeMask = void 0;
4
- /**
5
- * @module node-opcua-file-transfer-server
6
- */
7
- var OpenFileModeMask;
8
- (function (OpenFileModeMask) {
9
- OpenFileModeMask[OpenFileModeMask["ReadBit"] = 1] = "ReadBit";
10
- OpenFileModeMask[OpenFileModeMask["WriteBit"] = 2] = "WriteBit";
11
- OpenFileModeMask[OpenFileModeMask["EraseExistingBit"] = 4] = "EraseExistingBit";
12
- OpenFileModeMask[OpenFileModeMask["AppendBit"] = 8] = "AppendBit";
13
- })(OpenFileModeMask = exports.OpenFileModeMask || (exports.OpenFileModeMask = {}));
14
- var OpenFileMode;
15
- (function (OpenFileMode) {
16
- /**
17
- * Read bit 0 The file is opened for reading. If this bit is not
18
- * set the Read Method cannot be executed.
19
- */
20
- OpenFileMode[OpenFileMode["Read"] = 1] = "Read";
21
- /**
22
- * Write bit 1 The file is opened for writing. If this bit is not
23
- * set the Write Method cannot be executed.
24
- *
25
- */
26
- OpenFileMode[OpenFileMode["Write"] = 2] = "Write";
27
- OpenFileMode[OpenFileMode["ReadWrite"] = 3] = "ReadWrite";
28
- /**
29
- *
30
- * WriteEraseExisting
31
- * EraseExisting 2 This bit can only be set if the file is opened for writing
32
- * (Write bit is set). The existing content of the file is
33
- * erased and an empty file is provided.
34
- */
35
- OpenFileMode[OpenFileMode["WriteEraseExisting"] = 6] = "WriteEraseExisting";
36
- OpenFileMode[OpenFileMode["ReadWriteEraseExisting"] = 7] = "ReadWriteEraseExisting";
37
- /**
38
- * Append 3 When the Append bit is set the file is opened at end
39
- * of the file, otherwise at begin of the file.
40
- * The SetPosition Method can be used to change the position.
41
- */
42
- OpenFileMode[OpenFileMode["WriteAppend"] = 10] = "WriteAppend";
43
- OpenFileMode[OpenFileMode["ReadWriteAppend"] = 11] = "ReadWriteAppend";
44
- })(OpenFileMode = exports.OpenFileMode || (exports.OpenFileMode = {}));
45
- //# sourceMappingURL=open_mode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"open_mode.js","sourceRoot":"","sources":["../source/open_mode.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,gBAKX;AALD,WAAY,gBAAgB;IACxB,6DAAc,CAAA;IACd,+DAAe,CAAA;IACf,+EAAuB,CAAA;IACvB,iEAAgB,CAAA;AACpB,CAAC,EALW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAK3B;AAED,IAAY,YA8BX;AA9BD,WAAY,YAAY;IACpB;;;OAGG;IACH,+CAA+B,CAAA;IAC/B;;;;OAIG;IACH,iDAAiC,CAAA;IACjC,yDAAgE,CAAA;IAEhE;;;;;;OAMG;IACH,2EAAkF,CAAA;IAClF,mFAAiH,CAAA;IACjH;;;;OAIG;IACH,8DAAoE,CAAA;IACpE,sEAAmG,CAAA;AACvG,CAAC,EA9BW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QA8BvB"}
@@ -1,81 +0,0 @@
1
- /**
2
- * @module node-opcua-file-transfer
3
- */
4
- /// <reference types="node" />
5
- import { UAFile, UAFile_Base, UAObjectType } from "node-opcua-address-space";
6
- import { NodeIdLike } from "node-opcua-nodeid";
7
- import { AbstractFs } from "../common/abstract_fs";
8
- /**
9
- *
10
- */
11
- export interface FileOptions {
12
- /**
13
- * the filaname of the physical file which is managed by the OPCUA filetpye
14
- */
15
- filename: string;
16
- /**
17
- * the maximum allowed size of the phisical file.
18
- */
19
- maxSize?: number;
20
- /**
21
- * an optional mimeType
22
- */
23
- mimeType?: string;
24
- fileSystem?: AbstractFs;
25
- nodeId?: NodeIdLike;
26
- /**
27
- * the maximum number of bytes that can be read from the file
28
- * in a single read call
29
- * - if not specified or 0, we assume Int32 limit
30
- */
31
- maxChunkSize?: number;
32
- refreshFileContentFunc?: () => Promise<void>;
33
- }
34
- export interface UAFileType extends UAObjectType, UAFile_Base {
35
- }
36
- /**
37
- *
38
- */
39
- export declare class FileTypeData {
40
- _fs: AbstractFs;
41
- filename: string;
42
- maxSize: number;
43
- mimeType: string;
44
- maxChunkSizeBytes: number;
45
- private file;
46
- private _openCount;
47
- private _fileSize;
48
- static maxChunkSize: number;
49
- refreshFileContentFunc?: () => Promise<void>;
50
- constructor(options: FileOptions, file: UAFile);
51
- set openCount(value: number);
52
- get openCount(): number;
53
- set fileSize(value: number);
54
- get fileSize(): number;
55
- /**
56
- * refresh position and size
57
- * this method should be call by the server if the file
58
- * is modified externally
59
- *
60
- */
61
- refresh(): Promise<void>;
62
- refreshFileContent(): Promise<void>;
63
- }
64
- export declare function writeFile(fileSystem: AbstractFs, filename: string, content: Buffer): Promise<void>;
65
- /**
66
- * @private
67
- */
68
- export interface UAFileEx extends UAFile {
69
- $fileData: FileTypeData;
70
- }
71
- /**
72
- * @orivate
73
- */
74
- export declare function getFileData(opcuaFile2: UAFile): FileTypeData;
75
- export declare const defaultMaxSize = 100000000;
76
- /**
77
- * bind all methods of a UAFile OPCUA node
78
- * @param file the OPCUA Node that has a typeDefinition of FileType
79
- * @param options the options
80
- */
81
- export declare function installFileType(_file: UAFile, options: FileOptions): void;