
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
@node-wot/binding-file
Advanced tools
The protocol prefix handled by this binding is file://
.
In the following examples, how to use the File binding of node-wot is shown.
npm install @node-wot/core
npm install @node-wot/binding-file
test.txt
with contentThe example tries to load an internal TestThing TD and reads the fileContent
property, which exposes the content of the file test.txt
.
node example1.js
// example1.js
const { Servient } = require("@node-wot/core");
const { FileClientFactory } = require("@node-wot/binding-file");
// create Servient and add File binding
const servient = new Servient();
servient.addClientFactory(new FileClientFactory(null));
td = {
id: "urn:dev:wot:org:w3:testthing:file",
title: "TestThing",
"@type": "Thing",
security: ["nosec_sc"],
properties: {
fileContent: {
type: "string",
readOnly: true,
observable: false,
forms: [
{
href: "file:///test.txt",
contentType: "text/plain",
op: ["readproperty"],
},
],
},
},
securityDefinitions: {
nosec_sc: {
scheme: "nosec",
},
},
};
// try to read property that exposes the content of file test.txt
try {
servient.start().then(async (WoT) => {
const thing = await WoT.consume(td);
// read property "fileContent" and print the content
const read1 = await thing.readProperty("fileContent");
console.log("Content of File:\n", await read1.value());
});
} catch (err) {
console.error("Script error:", err);
}
The example tries to load a locally stored TestThing TD and reads the fileContent
property, which exposes the content of the file test.txt
.
TD.jsonld
with content as in Example 1node example2.js
// example2.js
const { Servient } = require("@node-wot/core");
const { FileClientFactory } = require("@node-wot/binding-file");
// create Servient and add File binding
const servient = new Servient();
servient.addClientFactory(new FileClientFactory(null));
servient
.start()
.then(async (WoT) => {
// using await for serial execution (note 'async' in then() of start())
try {
const td = await WoT.requestThingDescription("file:///TD.jsonld");
const thing = await WoT.consume(td);
// read property "fileContent" and print the content
const read1 = await thing.readProperty("fileContent");
console.log("Content of File:\n" + (await read1.value()));
} catch (err) {
console.error("Script error:", err);
}
})
.catch((err) => {
console.error("Fetch error:", err);
});
FAQs
File client protocol binding for node-wot
The npm package @node-wot/binding-file receives a total of 31 weekly downloads. As such, @node-wot/binding-file popularity was classified as not popular.
We found that @node-wot/binding-file demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.