node-opcua-file-transfer 2.112.0 → 2.114.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,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.readMaxByteStringLength = void 0;
13
4
  const node_opcua_basic_types_1 = require("node-opcua-basic-types");
@@ -15,17 +6,15 @@ const node_opcua_binary_stream_1 = require("node-opcua-binary-stream");
15
6
  const node_opcua_constants_1 = require("node-opcua-constants");
16
7
  const node_opcua_nodeid_1 = require("node-opcua-nodeid");
17
8
  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;
9
+ async function readMaxByteStringLength(session) {
10
+ const dataValue = await session.read({
11
+ nodeId: (0, node_opcua_nodeid_1.resolveNodeId)(node_opcua_constants_1.VariableIds.Server_ServerCapabilities_MaxByteStringLength),
12
+ attributeId: node_opcua_basic_types_1.AttributeIds.Value
28
13
  });
14
+ if (dataValue.statusCode !== node_opcua_status_code_1.StatusCodes.Good) {
15
+ return 1024;
16
+ }
17
+ return dataValue.value.value || node_opcua_binary_stream_1.BinaryStream.maxByteStringLength;
29
18
  }
30
19
  exports.readMaxByteStringLength = readMaxByteStringLength;
31
20
  //# sourceMappingURL=read_max_byte_string_length.js.map
@@ -1 +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"}
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;AAG9C,KAAK,UAAW,uBAAuB,CAAC,OAAsB;IACjE,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;QACjC,MAAM,EAAE,IAAA,iCAAa,EAAC,kCAAW,CAAC,6CAA6C,CAAC;QAChF,WAAW,EAAE,qCAAY,CAAC,KAAK;KAClC,CAAC,CAAC;IACH,IAAI,SAAS,CAAC,UAAU,KAAK,oCAAW,CAAC,IAAI,EAAE;QAC3C,OAAO,IAAI,CAAC;KACf;IACD,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,uCAAY,CAAC,mBAAmB,CAAC;AACrE,CAAC;AATD,0DASC"}
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  exports.writeOPCUAFile = void 0;
36
27
  const fs = __importStar(require("node:fs"));
@@ -47,42 +38,40 @@ const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("FileType");
47
38
  function getTransportMaxMessageSize(session) {
48
39
  return session.getTransportSettings ? session.getTransportSettings().maxMessageSize : 0;
49
40
  }
50
- function writeOPCUAFile(clientFile, filePath, { chunkSize }) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const maxMessageSize = getTransportMaxMessageSize(clientFile.session);
53
- chunkSize = chunkSize === undefined ? yield (0, read_max_byte_string_length_1.readMaxByteStringLength)(clientFile.session) : chunkSize;
54
- chunkSize = Math.min(chunkSize, node_opcua_binary_stream_1.BinaryStream.maxByteStringLength);
55
- if (maxMessageSize > 200) {
56
- chunkSize = Math.min(chunkSize, maxMessageSize - 1000);
57
- }
58
- if (!fs.existsSync(filePath)) {
59
- throw new Error(`File ${filePath} does not exist`);
60
- }
61
- const readStream = fs.createReadStream(filePath, { highWaterMark: chunkSize });
62
- yield clientFile.open(client_file_1.OpenFileMode.WriteEraseExisting);
63
- yield clientFile.setPosition(0);
64
- try {
65
- const outStream = new node_stream_1.Writable({
66
- write(chunk, encoding, callback) {
67
- doDebug && debugLog("writing chunk", chunk.length);
68
- clientFile
69
- .write(chunk)
70
- .then(() => callback())
71
- .catch((err) => callback(err));
72
- }
73
- });
74
- // note: pipeline requires NodeJS 15 or above
75
- yield (0, promises_1.pipeline)(readStream, outStream);
76
- }
77
- catch (e) {
78
- debugLog(e.message);
79
- throw e;
80
- }
81
- finally {
82
- doDebug && debugLog("closing the OPCUA File");
83
- yield clientFile.close();
84
- }
85
- });
41
+ async function writeOPCUAFile(clientFile, filePath, { chunkSize }) {
42
+ const maxMessageSize = getTransportMaxMessageSize(clientFile.session);
43
+ chunkSize = chunkSize === undefined ? await (0, read_max_byte_string_length_1.readMaxByteStringLength)(clientFile.session) : chunkSize;
44
+ chunkSize = Math.min(chunkSize, node_opcua_binary_stream_1.BinaryStream.maxByteStringLength);
45
+ if (maxMessageSize > 200) {
46
+ chunkSize = Math.min(chunkSize, maxMessageSize - 1000);
47
+ }
48
+ if (!fs.existsSync(filePath)) {
49
+ throw new Error(`File ${filePath} does not exist`);
50
+ }
51
+ const readStream = fs.createReadStream(filePath, { highWaterMark: chunkSize });
52
+ await clientFile.open(client_file_1.OpenFileMode.WriteEraseExisting);
53
+ await clientFile.setPosition(0);
54
+ try {
55
+ const outStream = new node_stream_1.Writable({
56
+ write(chunk, encoding, callback) {
57
+ doDebug && debugLog("writing chunk", chunk.length);
58
+ clientFile
59
+ .write(chunk)
60
+ .then(() => callback())
61
+ .catch((err) => callback(err));
62
+ }
63
+ });
64
+ // note: pipeline requires NodeJS 15 or above
65
+ await (0, promises_1.pipeline)(readStream, outStream);
66
+ }
67
+ catch (e) {
68
+ debugLog(e.message);
69
+ throw e;
70
+ }
71
+ finally {
72
+ doDebug && debugLog("closing the OPCUA File");
73
+ await clientFile.close();
74
+ }
86
75
  }
87
76
  exports.writeOPCUAFile = writeOPCUAFile;
88
77
  //# sourceMappingURL=write_file.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"write_file.js","sourceRoot":"","sources":["../../source/client/write_file.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;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,EAA0B;;QACjH,MAAM,cAAc,GAAG,0BAA0B,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAEtE,SAAS,GAAG,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,IAAA,qDAAuB,EAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACpG,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,uCAAY,CAAC,mBAAmB,CAAC,CAAC;QAClE,IAAI,cAAc,GAAG,GAAG,EAAE;YACtB,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,CAAC,CAAC;SAC1D;QAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,iBAAiB,CAAC,CAAC;SACtD;QAC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