npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-opcua-file-transfer

v2.124.0

Published

pure nodejs OPCUA SDK - module file-transfer

Downloads

7,771

Readme

introduction

this package provides an implementation of the OPCUA File Transfer specification as per OPCUA 1.0.4 part 5 Annex C (page 99)

installation

$ npm install node-opcua
$ npm install node-opcua-file-transfer

exposing a File node in the addressSpace

import { OPCUAServer, UAFile } from "node-opcua";
import { installFileType } from "node-opcua-file-transfer";

const server = new OPCUAServer({

});

await server.initialize();


// let say we want to create a access to this file:
const my_data_filename = "/data/someFile.txt";
await promisify(fs.writeFile)(my_data_filename, "some content", "utf8");


// now add a file object in the address Space
const addressSpace = server.engine.addressSpace;

// retrieve the FileType UAObjectType
const fileType = addressSpace.findObjectType("FileType")!;

// create a instance of FileType 
const myFile = fileType.instantiate({
    nodeId: "s=MyFile",
    browseName: "MyFile",
    organizedBy: addressSpace.rootFolder.objects
}) as UAFile;

// now bind the opcuaFile object with our file
installFileType(opcuaFile, { 
    filename: my_data_filename
});

accessing a File node from a node-opcua client : ClientFile

We assume that we have a valid OPCUA Client Session

import { OPCUAClient } from "node-opcua";
import { ClientFile } from "node-opcua-file-transfer";

const client = OPCUAClient.create({});

await client.connect();
const session = await client.createSession();

Let's assume that the nodeId of the file object is "ns=1;s=MyFile"

import {ClientFile,OpenFileMode } from "node-opcua-file-transfer";

// 
const fileNodeId = "ns=1;s=MyFile";

// let's create a client file object from the session and nodeId
const clientFile = new ClientFile(session, fileNodeId);

// let's open the file
const mode = OpenFileMode.ReadWriteAppend;
await clientFile.open(mode);

// ... do some reading or writing

// don't forget to close the file when done
await clientFile.close();

operations

ClientFile#size(): Promise : get file size

You can read the size of the file at any time.

const clientFile = new ClientFile(session, fileNodeId);

const size = await clientFile.size();
console.log("the current file size is : ",size," bytes);

ClientFile#open(mode: OpenFileMode) : open a file

const mode = OpenFileMode.ReadWriteAppend;
await clientFile.open(mode);

OpenFileMode enumeration

| Mode | Description | |------|-------------| | Read |The file is opened for reading. The Write method cannot be executed. | | Write|The file is opened for writing. The Read cannot be executed. | | ReadWrite| The file is opened for reading and writing | | WriteEraseExisting | File is open for writing only. The existing content of the file is erased and an empty file is provided. | | WriteAppend | File is open for writing only and the position is set at the end of the file | | ReadWriteAppend | File is opened for reading and writing and the position is set at the end of the file | }

ClientFile#close() : close a file

const mode = OpenFileMode.ReadWriteAppend;
await clientFile.open(mode);

// ... do some reading or writing

// don't forget to close the file when done
await clientFile.close();

ClientFile#setPosition(pos: UInt64) : Setting read/write position

Once the file is opened, the position for reading or writing can be set using setPosition.

  • setPosition expect a UInt64 parameter (see note below)
  • setPosition will throw an exception if file is not opened
const clientFile = new ClientFile(session, fileNodeId);

const mode = OpenFileMode.ReadWriteAppend;
await clientFile.open(mode);

await client.setPosition([0,32]);

ClientFile#getPosition(): Promise Getting read/write position

Once the file is opened, the position for reading or writing can be retrieved using getPosition.

  • getPosition returns a UInt64 parameter (see note below)
  • getPosition will throw an exception if file is not opened
const clientFile = new ClientFile(session, fileNodeId);

const mode = OpenFileMode.ReadWriteAppend;
await clientFile.open(mode);

await client.setPosition(32);

ClientFile#write(buf: Buffer) : Writing data to the file

Data can be writing to the file at the current cursor position. Data must be passed in a buffer.

  • write will throw an exception if file is not opened
const dataToWrite = Buffer.from("Some data");

const mode = OpenFileMode.ReadWriteAppend;
await clientFile.open(mode);
await clientFile.write(dataToWrite);

ClientFile#read(): Promise :reading data to the file

Data can be written to the file at the current cursor position. Data must be passed in a buffer.

  • read will throw an exception if the file is not opened

const mode = OpenFileMode.ReadWriteAppend;
await clientFile.open(mode);

// read 200 bytes from position 32
await clientFile.setPosition([0,32]);
const data: Buffer = await clientFile.read(200);

notes

UInt64

  • At this time BigInt, is not supported by all versions of nodeJs that are targeted by node-opcua. UInt64 values are currently stored into an array of 2 32bits numbers : [ High,Low]

Feature

| | | | |----------------------------------------|:------------------------:|--------------------| | FileType | :white_check_mark: | |
| FileDirectoryType | :new_moon: | (sponsor wanted) |
| FileTransferStateMachineType | :new_moon: | (sponsor wanted) |
| TemporaryFileTransferType | :new_moon: | (sponsor wanted) |
| AddressSpaceFileType | :new_moon: | (sponsor wanted) |

Sponsors & Backers

We appreciate that, once you have evaluated the software you consider supporting our effort by applying to our sponsor program:

  • https://github.com/sponsors/node-opcua
  • https://opencollective.com/node-opcua

Grants ensure the following:

  • 🔨 Long term maintenance of the project
  • ⚙️ maintain the website and continuous integration platform
  • 🛣 Progress on the road-map
  • 🐛 Quick responses to bug reports
  • 🚀 New features & enhancements
  • ⚖️ representing the node-opcua user community at the OPC Foundation

Support

Technical Support is exclusively provided to registered members of the NodeOPCUA Subscription (https://support.sterfive.com) or through dedicated Professional Services.

License

Node-OPCUA is made available to you under the MIT open source license.

See LICENSE for details.

value-added extensions

Contact Sterfive SAS (mailto:[email protected]) for additional companion modules that are available to registered members:

  • node-opcua-pub-sub : Part 14 implementation to develop OPC UA PubSub over MQTT applications
  • node-opcua-webproxy: to operate node-opcua from within a web browser
  • node-opcua-optimized-client: super-charge OPC UA Client
  • react-components: a collection of React UI components
  • aggregator: a powerful OPC UA aggregator that can combine and monitored hundred of servers and millions of variables.
  • node-opcua-gds: a Global Discovery Server (Part 12)
  • node-opcua-modeler-ex: a powerful NO-GUI OPC UA modeler

Copyright

Copyright (c) 2022-2024 Sterfive SAS - https://www.sterfive.com

Copyright (c) 2014-2022 Etienne Rossignon