node-opcua-file-transfer 2.52.0 → 2.56.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.
- package/LICENSE +20 -20
- package/package.json +22 -22
- package/readme.md +204 -204
- package/source/index.ts +5 -5
- package/source/open_mode.ts +41 -41
package/LICENSE
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014-2021 Etienne Rossignon
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
-
the Software without restriction, including without limitation the rights to
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
-
subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2021 Etienne Rossignon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-opcua-file-transfer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.56.0",
|
|
4
4
|
"description": "pure nodejs OPCUA SDK - module -server",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc -b",
|
|
@@ -11,31 +11,31 @@
|
|
|
11
11
|
"main": "./dist/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"node-opcua-address-space": "2.
|
|
15
|
-
"node-opcua-assert": "2.
|
|
16
|
-
"node-opcua-basic-types": "2.
|
|
17
|
-
"node-opcua-client": "2.
|
|
14
|
+
"node-opcua-address-space": "2.56.0",
|
|
15
|
+
"node-opcua-assert": "2.55.0",
|
|
16
|
+
"node-opcua-basic-types": "2.56.0",
|
|
17
|
+
"node-opcua-client": "2.56.0",
|
|
18
18
|
"node-opcua-constants": "2.52.0",
|
|
19
|
-
"node-opcua-data-model": "2.
|
|
20
|
-
"node-opcua-debug": "2.
|
|
21
|
-
"node-opcua-nodeid": "2.
|
|
19
|
+
"node-opcua-data-model": "2.56.0",
|
|
20
|
+
"node-opcua-debug": "2.55.0",
|
|
21
|
+
"node-opcua-nodeid": "2.55.0",
|
|
22
22
|
"node-opcua-nodesets": "2.51.0",
|
|
23
23
|
"node-opcua-pki": "^2.12.0",
|
|
24
|
-
"node-opcua-pseudo-session": "2.
|
|
25
|
-
"node-opcua-secure-channel": "2.
|
|
26
|
-
"node-opcua-server": "2.
|
|
27
|
-
"node-opcua-service-call": "2.
|
|
28
|
-
"node-opcua-service-read": "2.
|
|
29
|
-
"node-opcua-service-translate-browse-path": "2.
|
|
30
|
-
"node-opcua-status-code": "2.
|
|
31
|
-
"node-opcua-types": "2.
|
|
32
|
-
"node-opcua-variant": "2.
|
|
24
|
+
"node-opcua-pseudo-session": "2.56.0",
|
|
25
|
+
"node-opcua-secure-channel": "2.56.0",
|
|
26
|
+
"node-opcua-server": "2.56.0",
|
|
27
|
+
"node-opcua-service-call": "2.56.0",
|
|
28
|
+
"node-opcua-service-read": "2.56.0",
|
|
29
|
+
"node-opcua-service-translate-browse-path": "2.56.0",
|
|
30
|
+
"node-opcua-status-code": "2.56.0",
|
|
31
|
+
"node-opcua-types": "2.56.0",
|
|
32
|
+
"node-opcua-variant": "2.56.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"memfs": "^3.
|
|
36
|
-
"node-opcua-binary-stream": "2.
|
|
37
|
-
"node-opcua-data-value": "2.
|
|
38
|
-
"node-opcua-leak-detector": "2.
|
|
35
|
+
"memfs": "^3.3.0",
|
|
36
|
+
"node-opcua-binary-stream": "2.55.0",
|
|
37
|
+
"node-opcua-data-value": "2.56.0",
|
|
38
|
+
"node-opcua-leak-detector": "2.56.0",
|
|
39
39
|
"should": "^13.2.3",
|
|
40
40
|
"sinon": "^11.1.2"
|
|
41
41
|
},
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"internet of things"
|
|
55
55
|
],
|
|
56
56
|
"homepage": "http://node-opcua.github.io/",
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "9f6eac1c658c0d182fbe03cf58f799af468615eb"
|
|
58
58
|
}
|
package/readme.md
CHANGED
|
@@ -1,204 +1,204 @@
|
|
|
1
|
-
## introduction
|
|
2
|
-
|
|
3
|
-
this package provides an implementation of the OPCUA File Transfer
|
|
4
|
-
specification as per OPCUA 1.0.4 part 5 Annex C (page 99)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## installation
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
$ npm install node-opcua
|
|
11
|
-
$ npm install node-opcua-file-transfer
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## exposing a File node in the addressSpace
|
|
15
|
-
|
|
16
|
-
```javascript
|
|
17
|
-
import { OPCUAServer, UAFileType } from "node-opcua";
|
|
18
|
-
import { installFileType } from "node-opcua-file-transfer";
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
|
|
24
|
-
const server = new OPCUAServer({
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
await server.initialize();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// let say we want to create a access to this file:
|
|
32
|
-
const my_data_filename = "/data/someFile.txt";
|
|
33
|
-
await promisify(fs.writeFile)(my_data_filename, "some content", "utf8");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// now add a file object in the address Space
|
|
37
|
-
const addressSpace = server.engine.addressSpace;
|
|
38
|
-
|
|
39
|
-
// retrieve the FileType UAObjectType
|
|
40
|
-
const fileType = addressSpace.findObjectType("FileType")!;
|
|
41
|
-
|
|
42
|
-
// create a instance of FileType
|
|
43
|
-
const myFile = fileType.instantiate({
|
|
44
|
-
nodeId: "s=MyFile",
|
|
45
|
-
browseName: "MyFile",
|
|
46
|
-
organizedBy: addressSpace.rootFolder.objects
|
|
47
|
-
}) as UAFileType;
|
|
48
|
-
|
|
49
|
-
// now bind the opcuaFile object with our file
|
|
50
|
-
installFileType(opcuaFile, {
|
|
51
|
-
filename: my_data_filename
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
## accessing a File node from a node-opcua client : ClientFile
|
|
58
|
-
|
|
59
|
-
We assume that we have a valid OPCUA Client Session
|
|
60
|
-
|
|
61
|
-
```javascript
|
|
62
|
-
import { OPCUAClient } from "node-opcua";
|
|
63
|
-
import { ClientFile } from "node-opcua-file-transfer";
|
|
64
|
-
|
|
65
|
-
const client = OPCUAClient.create({});
|
|
66
|
-
|
|
67
|
-
await client.connect();
|
|
68
|
-
const session = await client.createSession();
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Let's assume that the nodeId of the file object is "ns=1;s=MyFile"
|
|
72
|
-
|
|
73
|
-
```javascript
|
|
74
|
-
import {ClientFile,OpenFileMode } from "node-opcua-file-transfer";
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
const fileNodeId = "ns=1;s=MyFile";
|
|
78
|
-
|
|
79
|
-
// let's create a client file object from the session and nodeId
|
|
80
|
-
const clientFile = new ClientFile(session, fileNodeId);
|
|
81
|
-
|
|
82
|
-
// let's open the file
|
|
83
|
-
const mode = OpenFileMode.ReadWriteAppend;
|
|
84
|
-
await clientFile.open(mode);
|
|
85
|
-
|
|
86
|
-
// ... do some reading or writing
|
|
87
|
-
|
|
88
|
-
// don't forget to close the file when done
|
|
89
|
-
await clientFile.close();
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### operations
|
|
93
|
-
|
|
94
|
-
#### ClientFile#size(): Promise<UInt64> : get file size
|
|
95
|
-
|
|
96
|
-
You can read the size of the file at any time.
|
|
97
|
-
``` javascript
|
|
98
|
-
const clientFile = new ClientFile(session, fileNodeId);
|
|
99
|
-
|
|
100
|
-
const size = await clientFile.size();
|
|
101
|
-
console.log("the current file size is : ",size," bytes);
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
#### ClientFile#open(mode: OpenFileMode) : open a file
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
const mode = OpenFileMode.ReadWriteAppend;
|
|
108
|
-
await clientFile.open(mode);
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
#### OpenFileMode enumeration
|
|
112
|
-
|
|
113
|
-
| Mode | Description |
|
|
114
|
-
|------|-------------|
|
|
115
|
-
| Read |The file is opened for reading. the Write method cannot be executed. |
|
|
116
|
-
| Write|The file is opened for writing. the Read cannot be executed. |
|
|
117
|
-
| ReadWrite| The file is opened for reading an writing |
|
|
118
|
-
| WriteEraseExisting | File is opened for writing only. The existing content of the file is erased and an empty file is provided. |
|
|
119
|
-
| ReadWriteEraseExisting | File is opened for reading and writing. The existing content of the file is erased and an empty file is provided.|
|
|
120
|
-
| WriteAppend | File is opened for writing only and position is set at the end of the file |
|
|
121
|
-
| ReadWriteAppend | File is opened for reading and writing and position is set at the end of the file |
|
|
122
|
-
}
|
|
123
|
-
#### ClientFile#close() : close a file
|
|
124
|
-
|
|
125
|
-
```javascript
|
|
126
|
-
const mode = OpenFileMode.ReadWriteAppend;
|
|
127
|
-
await clientFile.open(mode);
|
|
128
|
-
|
|
129
|
-
// ... do some reading or writing
|
|
130
|
-
|
|
131
|
-
// don't forget to close the file when done
|
|
132
|
-
await clientFile.close();
|
|
133
|
-
```
|
|
134
|
-
#### ClientFile#setPosition(pos: UInt64) : Setting read/write position
|
|
135
|
-
|
|
136
|
-
Once the file is opened, the position for reading or writing can be set
|
|
137
|
-
using setPosition.
|
|
138
|
-
* setPosition expect a UInt64 parameter (see note below)
|
|
139
|
-
* setPosition will throw an exception if file is not opened
|
|
140
|
-
|
|
141
|
-
``` javascript
|
|
142
|
-
const clientFile = new ClientFile(session, fileNodeId);
|
|
143
|
-
|
|
144
|
-
const mode = OpenFileMode.ReadWriteAppend;
|
|
145
|
-
await clientFile.open(mode);
|
|
146
|
-
|
|
147
|
-
await client.setPosition([0,32]);
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
#### ClientFile#getPosition(): Promise<UInt64> Getting read/write position
|
|
152
|
-
Once the file is opened, the position for reading or writing can be retrieved
|
|
153
|
-
using getPosition.
|
|
154
|
-
* getPosition returns a UInt64 parameter (see note below)
|
|
155
|
-
* getPosition will throw an exception if file is not opened
|
|
156
|
-
|
|
157
|
-
``` javascript
|
|
158
|
-
const clientFile = new ClientFile(session, fileNodeId);
|
|
159
|
-
|
|
160
|
-
const mode = OpenFileMode.ReadWriteAppend;
|
|
161
|
-
await clientFile.open(mode);
|
|
162
|
-
|
|
163
|
-
await client.setPosition(32);
|
|
164
|
-
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
#### ClientFile#write(buf: Buffer) : Writing data to the file
|
|
168
|
-
|
|
169
|
-
Data can be writing to the file at the current cursor position.
|
|
170
|
-
Data must be passed in a buffer.
|
|
171
|
-
* write will throw an exception if file is not opened
|
|
172
|
-
|
|
173
|
-
```javascript
|
|
174
|
-
const dataToWrite = Buffer.from("Some data");
|
|
175
|
-
|
|
176
|
-
const mode = OpenFileMode.ReadWriteAppend;
|
|
177
|
-
await clientFile.open(mode);
|
|
178
|
-
await clientFile.write(dataToWrite);
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
#### ClientFile#read(): Promise<Buffer> :reading data to the file
|
|
183
|
-
|
|
184
|
-
Data can be writing to the file at the current cursor position.
|
|
185
|
-
Data must be passed in a buffer.
|
|
186
|
-
* read will throw an exception if file is not opened
|
|
187
|
-
|
|
188
|
-
```javascript
|
|
189
|
-
|
|
190
|
-
const mode = OpenFileMode.ReadWriteAppend;
|
|
191
|
-
await clientFile.open(mode);
|
|
192
|
-
|
|
193
|
-
// read 200 bytes from position 32
|
|
194
|
-
await clientFile.setPosition([0,32]);
|
|
195
|
-
const data: Buffer = await clientFile.read(200);
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### notes
|
|
199
|
-
|
|
200
|
-
UInt64
|
|
201
|
-
* At this time BigInt, is not supported by all version of nodeJs that are targeted by node-opcua.
|
|
202
|
-
UInt64 values are currently stored into a array of 2 32bits numbers : [ High,Low]
|
|
203
|
-
|
|
204
|
-
|
|
1
|
+
## introduction
|
|
2
|
+
|
|
3
|
+
this package provides an implementation of the OPCUA File Transfer
|
|
4
|
+
specification as per OPCUA 1.0.4 part 5 Annex C (page 99)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ npm install node-opcua
|
|
11
|
+
$ npm install node-opcua-file-transfer
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## exposing a File node in the addressSpace
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
import { OPCUAServer, UAFileType } from "node-opcua";
|
|
18
|
+
import { installFileType } from "node-opcua-file-transfer";
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
|
|
24
|
+
const server = new OPCUAServer({
|
|
25
|
+
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
await server.initialize();
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// let say we want to create a access to this file:
|
|
32
|
+
const my_data_filename = "/data/someFile.txt";
|
|
33
|
+
await promisify(fs.writeFile)(my_data_filename, "some content", "utf8");
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
// now add a file object in the address Space
|
|
37
|
+
const addressSpace = server.engine.addressSpace;
|
|
38
|
+
|
|
39
|
+
// retrieve the FileType UAObjectType
|
|
40
|
+
const fileType = addressSpace.findObjectType("FileType")!;
|
|
41
|
+
|
|
42
|
+
// create a instance of FileType
|
|
43
|
+
const myFile = fileType.instantiate({
|
|
44
|
+
nodeId: "s=MyFile",
|
|
45
|
+
browseName: "MyFile",
|
|
46
|
+
organizedBy: addressSpace.rootFolder.objects
|
|
47
|
+
}) as UAFileType;
|
|
48
|
+
|
|
49
|
+
// now bind the opcuaFile object with our file
|
|
50
|
+
installFileType(opcuaFile, {
|
|
51
|
+
filename: my_data_filename
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## accessing a File node from a node-opcua client : ClientFile
|
|
58
|
+
|
|
59
|
+
We assume that we have a valid OPCUA Client Session
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
import { OPCUAClient } from "node-opcua";
|
|
63
|
+
import { ClientFile } from "node-opcua-file-transfer";
|
|
64
|
+
|
|
65
|
+
const client = OPCUAClient.create({});
|
|
66
|
+
|
|
67
|
+
await client.connect();
|
|
68
|
+
const session = await client.createSession();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Let's assume that the nodeId of the file object is "ns=1;s=MyFile"
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
import {ClientFile,OpenFileMode } from "node-opcua-file-transfer";
|
|
75
|
+
|
|
76
|
+
//
|
|
77
|
+
const fileNodeId = "ns=1;s=MyFile";
|
|
78
|
+
|
|
79
|
+
// let's create a client file object from the session and nodeId
|
|
80
|
+
const clientFile = new ClientFile(session, fileNodeId);
|
|
81
|
+
|
|
82
|
+
// let's open the file
|
|
83
|
+
const mode = OpenFileMode.ReadWriteAppend;
|
|
84
|
+
await clientFile.open(mode);
|
|
85
|
+
|
|
86
|
+
// ... do some reading or writing
|
|
87
|
+
|
|
88
|
+
// don't forget to close the file when done
|
|
89
|
+
await clientFile.close();
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### operations
|
|
93
|
+
|
|
94
|
+
#### ClientFile#size(): Promise<UInt64> : get file size
|
|
95
|
+
|
|
96
|
+
You can read the size of the file at any time.
|
|
97
|
+
``` javascript
|
|
98
|
+
const clientFile = new ClientFile(session, fileNodeId);
|
|
99
|
+
|
|
100
|
+
const size = await clientFile.size();
|
|
101
|
+
console.log("the current file size is : ",size," bytes);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### ClientFile#open(mode: OpenFileMode) : open a file
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
const mode = OpenFileMode.ReadWriteAppend;
|
|
108
|
+
await clientFile.open(mode);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### OpenFileMode enumeration
|
|
112
|
+
|
|
113
|
+
| Mode | Description |
|
|
114
|
+
|------|-------------|
|
|
115
|
+
| Read |The file is opened for reading. the Write method cannot be executed. |
|
|
116
|
+
| Write|The file is opened for writing. the Read cannot be executed. |
|
|
117
|
+
| ReadWrite| The file is opened for reading an writing |
|
|
118
|
+
| WriteEraseExisting | File is opened for writing only. The existing content of the file is erased and an empty file is provided. |
|
|
119
|
+
| ReadWriteEraseExisting | File is opened for reading and writing. The existing content of the file is erased and an empty file is provided.|
|
|
120
|
+
| WriteAppend | File is opened for writing only and position is set at the end of the file |
|
|
121
|
+
| ReadWriteAppend | File is opened for reading and writing and position is set at the end of the file |
|
|
122
|
+
}
|
|
123
|
+
#### ClientFile#close() : close a file
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
const mode = OpenFileMode.ReadWriteAppend;
|
|
127
|
+
await clientFile.open(mode);
|
|
128
|
+
|
|
129
|
+
// ... do some reading or writing
|
|
130
|
+
|
|
131
|
+
// don't forget to close the file when done
|
|
132
|
+
await clientFile.close();
|
|
133
|
+
```
|
|
134
|
+
#### ClientFile#setPosition(pos: UInt64) : Setting read/write position
|
|
135
|
+
|
|
136
|
+
Once the file is opened, the position for reading or writing can be set
|
|
137
|
+
using setPosition.
|
|
138
|
+
* setPosition expect a UInt64 parameter (see note below)
|
|
139
|
+
* setPosition will throw an exception if file is not opened
|
|
140
|
+
|
|
141
|
+
``` javascript
|
|
142
|
+
const clientFile = new ClientFile(session, fileNodeId);
|
|
143
|
+
|
|
144
|
+
const mode = OpenFileMode.ReadWriteAppend;
|
|
145
|
+
await clientFile.open(mode);
|
|
146
|
+
|
|
147
|
+
await client.setPosition([0,32]);
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### ClientFile#getPosition(): Promise<UInt64> Getting read/write position
|
|
152
|
+
Once the file is opened, the position for reading or writing can be retrieved
|
|
153
|
+
using getPosition.
|
|
154
|
+
* getPosition returns a UInt64 parameter (see note below)
|
|
155
|
+
* getPosition will throw an exception if file is not opened
|
|
156
|
+
|
|
157
|
+
``` javascript
|
|
158
|
+
const clientFile = new ClientFile(session, fileNodeId);
|
|
159
|
+
|
|
160
|
+
const mode = OpenFileMode.ReadWriteAppend;
|
|
161
|
+
await clientFile.open(mode);
|
|
162
|
+
|
|
163
|
+
await client.setPosition(32);
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### ClientFile#write(buf: Buffer) : Writing data to the file
|
|
168
|
+
|
|
169
|
+
Data can be writing to the file at the current cursor position.
|
|
170
|
+
Data must be passed in a buffer.
|
|
171
|
+
* write will throw an exception if file is not opened
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
const dataToWrite = Buffer.from("Some data");
|
|
175
|
+
|
|
176
|
+
const mode = OpenFileMode.ReadWriteAppend;
|
|
177
|
+
await clientFile.open(mode);
|
|
178
|
+
await clientFile.write(dataToWrite);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
#### ClientFile#read(): Promise<Buffer> :reading data to the file
|
|
183
|
+
|
|
184
|
+
Data can be writing to the file at the current cursor position.
|
|
185
|
+
Data must be passed in a buffer.
|
|
186
|
+
* read will throw an exception if file is not opened
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
|
|
190
|
+
const mode = OpenFileMode.ReadWriteAppend;
|
|
191
|
+
await clientFile.open(mode);
|
|
192
|
+
|
|
193
|
+
// read 200 bytes from position 32
|
|
194
|
+
await clientFile.setPosition([0,32]);
|
|
195
|
+
const data: Buffer = await clientFile.read(200);
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### notes
|
|
199
|
+
|
|
200
|
+
UInt64
|
|
201
|
+
* At this time BigInt, is not supported by all version of nodeJs that are targeted by node-opcua.
|
|
202
|
+
UInt64 values are currently stored into a array of 2 32bits numbers : [ High,Low]
|
|
203
|
+
|
|
204
|
+
|
package/source/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-file-transfer
|
|
3
|
-
*/
|
|
4
|
-
export * from "./client/client_file";
|
|
5
|
-
export * from "./server/file_type_helpers";
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-file-transfer
|
|
3
|
+
*/
|
|
4
|
+
export * from "./client/client_file";
|
|
5
|
+
export * from "./server/file_type_helpers";
|
package/source/open_mode.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module node-opcua-file-transfer-server
|
|
3
|
-
*/
|
|
4
|
-
export enum OpenFileModeMask {
|
|
5
|
-
ReadBit = 0x01,
|
|
6
|
-
WriteBit = 0x02,
|
|
7
|
-
EraseExistingBit = 0x04,
|
|
8
|
-
AppendBit = 0x08,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export enum OpenFileMode {
|
|
12
|
-
/**
|
|
13
|
-
* Read bit 0 The file is opened for reading. If this bit is not
|
|
14
|
-
* set the Read Method cannot be executed.
|
|
15
|
-
*/
|
|
16
|
-
Read = OpenFileModeMask.ReadBit,
|
|
17
|
-
/**
|
|
18
|
-
* Write bit 1 The file is opened for writing. If this bit is not
|
|
19
|
-
* set the Write Method cannot be executed.
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
Write = OpenFileModeMask.WriteBit,
|
|
23
|
-
ReadWrite = OpenFileModeMask.ReadBit + OpenFileModeMask.WriteBit,
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* WriteEraseExisting
|
|
28
|
-
* EraseExisting 2 This bit can only be set if the file is opened for writing
|
|
29
|
-
* (Write bit is set). The existing content of the file is
|
|
30
|
-
* erased and an empty file is provided.
|
|
31
|
-
*/
|
|
32
|
-
WriteEraseExisting = OpenFileModeMask.EraseExistingBit + OpenFileModeMask.WriteBit,
|
|
33
|
-
ReadWriteEraseExisting = OpenFileModeMask.EraseExistingBit + OpenFileModeMask.WriteBit + OpenFileModeMask.ReadBit,
|
|
34
|
-
/**
|
|
35
|
-
* Append 3 When the Append bit is set the file is opened at end
|
|
36
|
-
* of the file, otherwise at begin of the file.
|
|
37
|
-
* The SetPosition Method can be used to change the position.
|
|
38
|
-
*/
|
|
39
|
-
WriteAppend = OpenFileModeMask.AppendBit + OpenFileModeMask.WriteBit,
|
|
40
|
-
ReadWriteAppend = OpenFileModeMask.AppendBit + OpenFileModeMask.WriteBit + OpenFileModeMask.ReadBit,
|
|
41
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @module node-opcua-file-transfer-server
|
|
3
|
+
*/
|
|
4
|
+
export enum OpenFileModeMask {
|
|
5
|
+
ReadBit = 0x01,
|
|
6
|
+
WriteBit = 0x02,
|
|
7
|
+
EraseExistingBit = 0x04,
|
|
8
|
+
AppendBit = 0x08,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export enum OpenFileMode {
|
|
12
|
+
/**
|
|
13
|
+
* Read bit 0 The file is opened for reading. If this bit is not
|
|
14
|
+
* set the Read Method cannot be executed.
|
|
15
|
+
*/
|
|
16
|
+
Read = OpenFileModeMask.ReadBit,
|
|
17
|
+
/**
|
|
18
|
+
* Write bit 1 The file is opened for writing. If this bit is not
|
|
19
|
+
* set the Write Method cannot be executed.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
Write = OpenFileModeMask.WriteBit,
|
|
23
|
+
ReadWrite = OpenFileModeMask.ReadBit + OpenFileModeMask.WriteBit,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* WriteEraseExisting
|
|
28
|
+
* EraseExisting 2 This bit can only be set if the file is opened for writing
|
|
29
|
+
* (Write bit is set). The existing content of the file is
|
|
30
|
+
* erased and an empty file is provided.
|
|
31
|
+
*/
|
|
32
|
+
WriteEraseExisting = OpenFileModeMask.EraseExistingBit + OpenFileModeMask.WriteBit,
|
|
33
|
+
ReadWriteEraseExisting = OpenFileModeMask.EraseExistingBit + OpenFileModeMask.WriteBit + OpenFileModeMask.ReadBit,
|
|
34
|
+
/**
|
|
35
|
+
* Append 3 When the Append bit is set the file is opened at end
|
|
36
|
+
* of the file, otherwise at begin of the file.
|
|
37
|
+
* The SetPosition Method can be used to change the position.
|
|
38
|
+
*/
|
|
39
|
+
WriteAppend = OpenFileModeMask.AppendBit + OpenFileModeMask.WriteBit,
|
|
40
|
+
ReadWriteAppend = OpenFileModeMask.AppendBit + OpenFileModeMask.WriteBit + OpenFileModeMask.ReadBit,
|
|
41
|
+
}
|