node-opcua-file-transfer 2.98.0 → 2.98.2

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.
@@ -0,0 +1,92 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * @module node-opcua-file-transfer
4
+ */
5
+ import { Int32, Int64, UInt16, UInt32, UInt64 } from "node-opcua-basic-types";
6
+ import { NodeId } from "node-opcua-nodeid";
7
+ import { IBasicSession } from "node-opcua-pseudo-session";
8
+ import { OpenFileMode } from "../open_mode";
9
+ export { OpenFileMode } from "../open_mode";
10
+ export interface IClientFile {
11
+ fileHandle: number;
12
+ open(mode: OpenFileMode): Promise<number>;
13
+ close(): Promise<void>;
14
+ getPosition(): Promise<UInt64>;
15
+ setPosition(position: UInt64 | UInt32): Promise<void>;
16
+ read(bytesToRead: UInt32 | Int32 | Int64 | UInt64): Promise<Buffer>;
17
+ write(data: Buffer): Promise<void>;
18
+ openCount(): Promise<UInt16>;
19
+ size(): Promise<UInt64>;
20
+ session: IBasicSession;
21
+ }
22
+ export interface IClientFilePriv extends IClientFile {
23
+ readonly fileNodeId: NodeId;
24
+ openMethodNodeId?: NodeId;
25
+ closeMethodNodeId?: NodeId;
26
+ setPositionNodeId?: NodeId;
27
+ getPositionNodeId?: NodeId;
28
+ readNodeId?: NodeId;
29
+ writeNodeId?: NodeId;
30
+ openCountNodeId?: NodeId;
31
+ sizeNodeId?: NodeId;
32
+ ensureInitialized(): Promise<void>;
33
+ }
34
+ /**
35
+ *
36
+ *
37
+ */
38
+ export declare class ClientFile implements IClientFile {
39
+ static useGlobalMethod: boolean;
40
+ fileHandle: number;
41
+ session: IBasicSession;
42
+ protected readonly fileNodeId: NodeId;
43
+ private openMethodNodeId?;
44
+ private closeMethodNodeId?;
45
+ private setPositionNodeId?;
46
+ private getPositionNodeId?;
47
+ private readNodeId?;
48
+ private writeNodeId?;
49
+ private openCountNodeId?;
50
+ private sizeNodeId?;
51
+ constructor(session: IBasicSession, nodeId: NodeId);
52
+ open(mode: OpenFileMode): Promise<number>;
53
+ close(): Promise<void>;
54
+ getPosition(): Promise<UInt64>;
55
+ setPosition(position: UInt64 | UInt32): Promise<void>;
56
+ read(bytesToRead: UInt32 | Int32 | Int64 | UInt64): Promise<Buffer>;
57
+ write(data: Buffer): Promise<void>;
58
+ openCount(): Promise<UInt16>;
59
+ size(): Promise<UInt64>;
60
+ protected extractMethodsIds(): Promise<void>;
61
+ protected ensureInitialized(): Promise<void>;
62
+ }
63
+ /**
64
+ * 5.2.10 UserRolePermissions
65
+ *
66
+ * The optional UserRolePermissions Attribute specifies the Permissions that apply to a Node for
67
+ * all Roles granted to current Session. The value of the Attribute is an array of
68
+ * RolePermissionType Structures (see Table 8).
69
+ * Clients may determine their effective Permissions by logically ORing the Permissions for each
70
+ * Role in the array.
71
+ * The value of this Attribute is derived from the rules used by the Server to map Sessions to
72
+ * Roles. This mapping may be vendor specific or it may use the standard Role model defined in 4.8.
73
+ * This Attribute shall not be writeable.
74
+ * If not specified, the value of DefaultUserRolePermissions Property from the Namespace
75
+ * Metadata Object associated with the Node is used instead. If the NamespaceMetadata Object
76
+ * does not define the Property or does not exist, then the Server does not publish any information
77
+ * about Roles mapped to the current Session.
78
+ *
79
+ *
80
+ * 5.2.11 AccessRestrictions
81
+ * The optional AccessRestrictions Attribute specifies the AccessRestrictions that apply to a Node.
82
+ * Its data type is defined in 8.56. If a Server supports AccessRestrictions for a particular
83
+ * Namespace it adds the DefaultAccessRestrictions Property to the NamespaceMetadata Object
84
+ * for that Namespace (see Figure 8). If a particular Node in the Namespace needs to override
85
+ * the default value the Server adds the AccessRestrictions Attribute to the Node.
86
+ * If a Server implements a vendor specific access restriction model for a Namespace, it does not
87
+ * add the DefaultAccessRestrictions Property to the NamespaceMetadata Object.
88
+ *
89
+ *
90
+ * DefaultAccessRestrictions
91
+ *
92
+ */
@@ -0,0 +1,307 @@
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.ClientFile = exports.OpenFileMode = void 0;
13
+ /**
14
+ * @module node-opcua-file-transfer
15
+ */
16
+ const node_opcua_basic_types_1 = require("node-opcua-basic-types");
17
+ const node_opcua_data_model_1 = require("node-opcua-data-model");
18
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
19
+ const node_opcua_service_translate_browse_path_1 = require("node-opcua-service-translate-browse-path");
20
+ const node_opcua_variant_1 = require("node-opcua-variant");
21
+ const node_opcua_constants_1 = require("node-opcua-constants");
22
+ const node_opcua_debug_1 = require("node-opcua-debug");
23
+ const debugLog = (0, node_opcua_debug_1.make_debugLog)("FileType");
24
+ const errorLog = (0, node_opcua_debug_1.make_errorLog)("FileType");
25
+ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("FileType");
26
+ const open_mode_1 = require("../open_mode");
27
+ var open_mode_2 = require("../open_mode");
28
+ Object.defineProperty(exports, "OpenFileMode", { enumerable: true, get: function () { return open_mode_2.OpenFileMode; } });
29
+ /**
30
+ *
31
+ *
32
+ */
33
+ class ClientFile {
34
+ constructor(session, nodeId) {
35
+ this.fileHandle = 0;
36
+ this.session = session;
37
+ this.fileNodeId = nodeId;
38
+ }
39
+ open(mode) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ if (mode === null || mode === undefined) {
42
+ throw new Error("expecting a validMode " + open_mode_1.OpenFileMode[mode]);
43
+ }
44
+ if (this.fileHandle) {
45
+ throw new Error("File has already be opened");
46
+ }
47
+ yield this.ensureInitialized();
48
+ const result = yield this.session.call({
49
+ inputArguments: [{ dataType: node_opcua_variant_1.DataType.Byte, value: mode }],
50
+ methodId: this.openMethodNodeId,
51
+ objectId: this.fileNodeId
52
+ });
53
+ if (result.statusCode.isNotGood()) {
54
+ debugLog("Cannot open file : ");
55
+ throw new Error("cannot open file statusCode = " + result.statusCode.toString() + " mode = " + open_mode_1.OpenFileMode[mode]);
56
+ }
57
+ this.fileHandle = result.outputArguments[0].value;
58
+ return this.fileHandle;
59
+ });
60
+ }
61
+ close() {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ if (!this.fileHandle) {
64
+ throw new Error("File has not been opened yet");
65
+ }
66
+ yield this.ensureInitialized();
67
+ const result = yield this.session.call({
68
+ inputArguments: [{ dataType: node_opcua_variant_1.DataType.UInt32, value: this.fileHandle }],
69
+ methodId: this.closeMethodNodeId,
70
+ objectId: this.fileNodeId
71
+ });
72
+ if (result.statusCode.isNotGood()) {
73
+ debugLog("Cannot close file : ");
74
+ throw new Error("cannot close file statusCode = " + result.statusCode.toString());
75
+ }
76
+ this.fileHandle = 0;
77
+ });
78
+ }
79
+ getPosition() {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ yield this.ensureInitialized();
82
+ if (!this.fileHandle) {
83
+ throw new Error("File has not been opened yet");
84
+ }
85
+ const result = yield this.session.call({
86
+ inputArguments: [{ dataType: node_opcua_variant_1.DataType.UInt32, value: this.fileHandle }],
87
+ methodId: this.getPositionNodeId,
88
+ objectId: this.fileNodeId
89
+ });
90
+ if (result.statusCode.isNotGood()) {
91
+ throw new Error("Error " + result.statusCode.toString());
92
+ }
93
+ return result.outputArguments[0].value;
94
+ });
95
+ }
96
+ setPosition(position) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ yield this.ensureInitialized();
99
+ if (!this.fileHandle) {
100
+ throw new Error("File has not been opened yet");
101
+ }
102
+ if (typeof position === "number") {
103
+ position = [0, position];
104
+ }
105
+ const result = yield this.session.call({
106
+ inputArguments: [
107
+ { dataType: node_opcua_variant_1.DataType.UInt32, value: this.fileHandle },
108
+ {
109
+ arrayType: node_opcua_variant_1.VariantArrayType.Scalar,
110
+ dataType: node_opcua_variant_1.DataType.UInt64,
111
+ value: position
112
+ }
113
+ ],
114
+ methodId: this.setPositionNodeId,
115
+ objectId: this.fileNodeId
116
+ });
117
+ if (result.statusCode.isNotGood()) {
118
+ throw new Error("Error " + result.statusCode.toString());
119
+ }
120
+ return;
121
+ });
122
+ }
123
+ read(bytesToRead) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ yield this.ensureInitialized();
126
+ if (!this.fileHandle) {
127
+ throw new Error("File has not been opened yet");
128
+ }
129
+ const result = yield this.session.call({
130
+ inputArguments: [
131
+ { dataType: node_opcua_variant_1.DataType.UInt32, value: this.fileHandle },
132
+ {
133
+ arrayType: node_opcua_variant_1.VariantArrayType.Scalar,
134
+ dataType: node_opcua_variant_1.DataType.Int32,
135
+ value: (0, node_opcua_basic_types_1.coerceInt32)(bytesToRead)
136
+ }
137
+ ],
138
+ methodId: this.readNodeId,
139
+ objectId: this.fileNodeId
140
+ });
141
+ if (result.statusCode.isNotGood()) {
142
+ throw new Error("Error " + result.statusCode.toString());
143
+ }
144
+ if (!result.outputArguments || result.outputArguments[0].dataType !== node_opcua_variant_1.DataType.ByteString) {
145
+ throw new Error("Error invalid output");
146
+ }
147
+ return result.outputArguments[0].value;
148
+ });
149
+ }
150
+ write(data) {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ yield this.ensureInitialized();
153
+ if (!this.fileHandle) {
154
+ throw new Error("File has not been opened yet");
155
+ }
156
+ const result = yield this.session.call({
157
+ inputArguments: [
158
+ { dataType: node_opcua_variant_1.DataType.UInt32, value: this.fileHandle },
159
+ {
160
+ arrayType: node_opcua_variant_1.VariantArrayType.Scalar,
161
+ dataType: node_opcua_variant_1.DataType.ByteString,
162
+ value: data
163
+ }
164
+ ],
165
+ methodId: this.writeNodeId,
166
+ objectId: this.fileNodeId
167
+ });
168
+ if (result.statusCode.isNotGood()) {
169
+ throw new Error("Error " + result.statusCode.toString());
170
+ }
171
+ return;
172
+ });
173
+ }
174
+ openCount() {
175
+ return __awaiter(this, void 0, void 0, function* () {
176
+ yield this.ensureInitialized();
177
+ const nodeToRead = { nodeId: this.openCountNodeId, attributeId: node_opcua_data_model_1.AttributeIds.Value };
178
+ const dataValue = yield this.session.read(nodeToRead);
179
+ if (doDebug) {
180
+ debugLog(" OpenCount ", nodeToRead.nodeId.toString(), dataValue.toString());
181
+ }
182
+ return dataValue.value.value;
183
+ });
184
+ }
185
+ size() {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ yield this.ensureInitialized();
188
+ const nodeToRead = { nodeId: this.sizeNodeId, attributeId: node_opcua_data_model_1.AttributeIds.Value };
189
+ const dataValue = yield this.session.read(nodeToRead);
190
+ return dataValue.value.value;
191
+ });
192
+ }
193
+ // eslint-disable-next-line max-statements
194
+ extractMethodsIds() {
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ if (ClientFile.useGlobalMethod) {
197
+ debugLog("Using GlobalMethodId");
198
+ this.openMethodNodeId = (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.MethodIds.FileType_Open);
199
+ this.closeMethodNodeId = (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.MethodIds.FileType_Close);
200
+ this.setPositionNodeId = (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.MethodIds.FileType_SetPosition);
201
+ this.getPositionNodeId = (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.MethodIds.FileType_GetPosition);
202
+ this.writeNodeId = (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.MethodIds.FileType_Write);
203
+ this.readNodeId = (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.MethodIds.FileType_Read);
204
+ const browsePaths = [
205
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/OpenCount"),
206
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/Size")
207
+ ];
208
+ const results = yield this.session.translateBrowsePath(browsePaths);
209
+ if (results[0].statusCode.isNotGood()) {
210
+ throw new Error("fileType object does not expose mandatory OpenCount Property");
211
+ }
212
+ if (results[1].statusCode.isNotGood()) {
213
+ throw new Error("fileType object does not expose mandatory Size Property");
214
+ }
215
+ this.openCountNodeId = results[0].targets[0].targetId;
216
+ this.sizeNodeId = results[1].targets[0].targetId;
217
+ return;
218
+ }
219
+ const browsePaths = [
220
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/Open"),
221
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/Close"),
222
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/SetPosition"),
223
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/GetPosition"),
224
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/Write"),
225
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/Read"),
226
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/OpenCount"),
227
+ (0, node_opcua_service_translate_browse_path_1.makeBrowsePath)(this.fileNodeId, "/Size")
228
+ ];
229
+ const results = yield this.session.translateBrowsePath(browsePaths);
230
+ if (results[0].statusCode.isNotGood()) {
231
+ throw new Error("fileType object does not expose mandatory Open Method");
232
+ }
233
+ if (results[1].statusCode.isNotGood()) {
234
+ throw new Error("fileType object does not expose mandatory Close Method");
235
+ }
236
+ if (results[2].statusCode.isNotGood()) {
237
+ throw new Error("fileType object does not expose mandatory SetPosition Method");
238
+ }
239
+ if (results[3].statusCode.isNotGood()) {
240
+ throw new Error("fileType object does not expose mandatory GetPosition Method");
241
+ }
242
+ if (results[4].statusCode.isNotGood()) {
243
+ throw new Error("fileType object does not expose mandatory Write Method");
244
+ }
245
+ if (results[5].statusCode.isNotGood()) {
246
+ throw new Error("fileType object does not expose mandatory Read Method");
247
+ }
248
+ if (results[6].statusCode.isNotGood()) {
249
+ throw new Error("fileType object does not expose mandatory OpenCount Variable");
250
+ }
251
+ if (results[7].statusCode.isNotGood()) {
252
+ throw new Error("fileType object does not expose mandatory Size Variable");
253
+ }
254
+ if (false && doDebug) {
255
+ results.map((x) => debugLog(x.toString()));
256
+ }
257
+ this.openMethodNodeId = results[0].targets[0].targetId;
258
+ this.closeMethodNodeId = results[1].targets[0].targetId;
259
+ this.setPositionNodeId = results[2].targets[0].targetId;
260
+ this.getPositionNodeId = results[3].targets[0].targetId;
261
+ this.writeNodeId = results[4].targets[0].targetId;
262
+ this.readNodeId = results[5].targets[0].targetId;
263
+ this.openCountNodeId = results[6].targets[0].targetId;
264
+ this.sizeNodeId = results[7].targets[0].targetId;
265
+ });
266
+ }
267
+ ensureInitialized() {
268
+ return __awaiter(this, void 0, void 0, function* () {
269
+ if (!this.openMethodNodeId) {
270
+ yield this.extractMethodsIds();
271
+ }
272
+ });
273
+ }
274
+ }
275
+ ClientFile.useGlobalMethod = false;
276
+ exports.ClientFile = ClientFile;
277
+ /**
278
+ * 5.2.10 UserRolePermissions
279
+ *
280
+ * The optional UserRolePermissions Attribute specifies the Permissions that apply to a Node for
281
+ * all Roles granted to current Session. The value of the Attribute is an array of
282
+ * RolePermissionType Structures (see Table 8).
283
+ * Clients may determine their effective Permissions by logically ORing the Permissions for each
284
+ * Role in the array.
285
+ * The value of this Attribute is derived from the rules used by the Server to map Sessions to
286
+ * Roles. This mapping may be vendor specific or it may use the standard Role model defined in 4.8.
287
+ * This Attribute shall not be writeable.
288
+ * If not specified, the value of DefaultUserRolePermissions Property from the Namespace
289
+ * Metadata Object associated with the Node is used instead. If the NamespaceMetadata Object
290
+ * does not define the Property or does not exist, then the Server does not publish any information
291
+ * about Roles mapped to the current Session.
292
+ *
293
+ *
294
+ * 5.2.11 AccessRestrictions
295
+ * The optional AccessRestrictions Attribute specifies the AccessRestrictions that apply to a Node.
296
+ * Its data type is defined in 8.56. If a Server supports AccessRestrictions for a particular
297
+ * Namespace it adds the DefaultAccessRestrictions Property to the NamespaceMetadata Object
298
+ * for that Namespace (see Figure 8). If a particular Node in the Namespace needs to override
299
+ * the default value the Server adds the AccessRestrictions Attribute to the Node.
300
+ * If a Server implements a vendor specific access restriction model for a Namespace, it does not
301
+ * add the DefaultAccessRestrictions Property to the NamespaceMetadata Object.
302
+ *
303
+ *
304
+ * DefaultAccessRestrictions
305
+ *
306
+ */
307
+ //# sourceMappingURL=client_file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client_file.js","sourceRoot":"","sources":["../../source/client/client_file.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;GAEG;AACH,mEAAiG;AACjG,iEAAqD;AACrD,yDAA0D;AAG1D,uGAAsF;AACtF,2DAAgE;AAChE,+DAAiD;AAEjD,uDAAgF;AAEhF,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,OAAO,GAAG,IAAA,iCAAc,EAAC,UAAU,CAAC,CAAC;AAE3C,4CAA4C;AAC5C,0CAA4C;AAAnC,yGAAA,YAAY,OAAA;AA4BrB;;;GAGG;AACH,MAAa,UAAU;IAgBnB,YAAY,OAAsB,EAAE,MAAc;QAb3C,eAAU,GAAG,CAAC,CAAC;QAclB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;IAC7B,CAAC;IAEY,IAAI,CAAC,IAAkB;;YAChC,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE;gBACrC,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,wBAAY,CAAC,IAAI,CAAC,CAAC,CAAC;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G"}
@@ -0,0 +1,3 @@
1
+ export * from "./client_file";
2
+ export * from "./read_file";
3
+ export * from "./write_file";
@@ -0,0 +1,20 @@
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("./client_file"), exports);
18
+ __exportStar(require("./read_file"), exports);
19
+ __exportStar(require("./write_file"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,8CAA4B;AAC5B,+CAA6B"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import { IClientFile } from "./client_file";
3
+ export declare function readFile(clientFile: IClientFile, options?: {
4
+ chunkSize?: number;
5
+ }): Promise<Buffer>;
6
+ export declare function readOPCUAFile(clientFile: IClientFile): Promise<Buffer>;
@@ -0,0 +1,60 @@
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.readOPCUAFile = exports.readFile = void 0;
13
+ const node_opcua_basic_types_1 = require("node-opcua-basic-types");
14
+ const client_file_1 = require("./client_file");
15
+ const read_max_byte_string_length_1 = require("./read_max_byte_string_length");
16
+ function getTransportMaxMessageSize(session) {
17
+ return session.getTransportSettings ? session.getTransportSettings().maxMessageSize : 0;
18
+ }
19
+ function readFile(clientFile, options) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ options = options || { chunkSize: yield (0, read_max_byte_string_length_1.readMaxByteStringLength)(clientFile.session) };
22
+ let maxBlockSize = options.chunkSize || 1024;
23
+ const transportMaxSize = getTransportMaxMessageSize(clientFile.session);
24
+ maxBlockSize = transportMaxSize > 0 ? Math.min(maxBlockSize, transportMaxSize) : maxBlockSize;
25
+ yield clientFile.open(client_file_1.OpenFileMode.Read);
26
+ try {
27
+ const fileSize = (0, node_opcua_basic_types_1.coerceInt32)(yield clientFile.size());
28
+ /**
29
+ * Read file
30
+ */
31
+ const data = yield clientFile.read(Math.min(fileSize, maxBlockSize));
32
+ if (data.length >= fileSize) {
33
+ // everything has been read
34
+ return data;
35
+ }
36
+ // wee need to loop to complete the read
37
+ const chunks = [data];
38
+ let remaining = fileSize - data.length;
39
+ while (remaining > 0) {
40
+ const buf = yield clientFile.read(Math.min(remaining, maxBlockSize));
41
+ if (buf.length === 0)
42
+ break;
43
+ chunks.push(buf);
44
+ remaining -= buf.length;
45
+ }
46
+ return Buffer.concat(chunks);
47
+ }
48
+ finally {
49
+ yield clientFile.close();
50
+ }
51
+ });
52
+ }
53
+ exports.readFile = readFile;
54
+ function readOPCUAFile(clientFile) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ return yield readFile(clientFile);
57
+ });
58
+ }
59
+ exports.readOPCUAFile = readOPCUAFile;
60
+ //# sourceMappingURL=read_file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read_file.js","sourceRoot":"","sources":["../../source/client/read_file.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mEAAqD;AAErD,+CAA0D;AAC1D,+EAAwE;AAExE,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,QAAQ,CAAC,UAAuB,EAAE,OAAgC;;QACpF,OAAO,GAAG,OAAO,IAAI,EAAE,SAAS,EAAE,MAAM,IAAA,qDAAuB,EAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACtF,IAAI,YAAY,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;QAC7C,MAAM,gBAAgB,GAAG,0BAA0B,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACxE,YAAY,GAAG,gBAAgB,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;QAE9F,MAAM,UAAU,CAAC,IAAI,CAAC,0BAAY,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI;YACA,MAAM,QAAQ,GAAG,IAAA,oCAAW,EAAC,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;YACtD;;eAEG;YACH,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;YACrE,IAAI,IAAI,CAAC,MAAM,IAAI,QAAQ,EAAE;gBACzB,2BAA2B;gBAC3B,OAAO,IAAI,CAAC;aACf;YAED,wCAAwC;YACxC,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC;YACtB,IAAI,SAAS,GAAG,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC;YACvC,OAAO,SAAS,GAAG,CAAC,EAAE;gBAClB,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;gBACrE,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;oBAAE,MAAM;gBAC5B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACjB,SAAS,IAAI,GAAG,CAAC,MAAM,CAAC;aAC3B;YACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SAChC;gBAAS;YACN,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;SAC5B;IACL,CAAC;CAAA;AA/BD,4BA+BC;AAED,SAAsB,aAAa,CAAC,UAAuB;;QACvD,OAAO,MAAM,QAAQ,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;CAAA;AAFD,sCAEC"}
@@ -0,0 +1,2 @@
1
+ import { IBasicSession } from "node-opcua-pseudo-session";
2
+ export declare function readMaxByteStringLength(session: IBasicSession): Promise<number>;
@@ -0,0 +1,31 @@
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.readMaxByteStringLength = void 0;
13
+ const node_opcua_basic_types_1 = require("node-opcua-basic-types");
14
+ const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
15
+ const node_opcua_constants_1 = require("node-opcua-constants");
16
+ const node_opcua_nodeid_1 = require("node-opcua-nodeid");
17
+ const node_opcua_status_code_1 = require("node-opcua-status-code");
18
+ function readMaxByteStringLength(session) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const dataValue = yield session.read({
21
+ nodeId: (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.VariableIds.Server_ServerCapabilities_MaxByteStringLength),
22
+ attributeId: node_opcua_basic_types_1.AttributeIds.Value
23
+ });
24
+ if (dataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
25
+ return 1024;
26
+ }
27
+ return dataValue.value.value || node_opcua_binary_stream_1.BinaryStream.maxByteStringLength;
28
+ });
29
+ }
30
+ exports.readMaxByteStringLength = readMaxByteStringLength;
31
+ //# sourceMappingURL=read_max_byte_string_length.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read_max_byte_string_length.js","sourceRoot":"","sources":["../../source/client/read_max_byte_string_length.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mEAAsD;AACtD,uEAAwD;AACxD,+DAAmD;AACnD,yDAAkD;AAElD,mEAAqD;AAGrD,SAAuB,uBAAuB,CAAC,OAAsB;;QACjE,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YACjC,MAAM,EAAE,IAAA,iCAAa,EAAC,kCAAW,CAAC,6CAA6C,CAAC;YAChF,WAAW,EAAE,qCAAY,CAAC,KAAK;SAClC,CAAC,CAAC;QACH,IAAI,SAAS,CAAC,UAAU,KAAK,oCAAW,CAAC,IAAI,EAAE;YAC3C,OAAO,IAAI,CAAC;SACf;QACD,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,uCAAY,CAAC,mBAAmB,CAAC;IACrE,CAAC;CAAA;AATD,0DASC"}
@@ -0,0 +1,4 @@
1
+ import { IClientFile } from "./client_file";
2
+ export declare function writeOPCUAFile(clientFile: IClientFile, filePath: string, { chunkSize }: {
3
+ chunkSize?: number;
4
+ }): Promise<void>;
@@ -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
+ 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
@@ -0,0 +1 @@
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,UAAu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