0.8.13 • Published 1 month ago

@node-wot/binding-file v0.8.13

Weekly downloads
11
License
EPL-2.0 OR W3C-20...
Repository
github
Last release
1 month ago

File Binding of node-wot

Protocol specifier

The protocol prefix handled by this binding is file://.

Getting Started

In the following examples, how to use the File binding of node-wot is shown.

Prerequisites

  • npm install @node-wot/core
  • npm install @node-wot/binding-file
  • local test file test.txt with content

Example 1

The 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);
}

Example 2

The example tries to load a locally stored TestThing TD and reads the fileContent property, which exposes the content of the file test.txt.

Prerequisites

  • local TD file TD.jsonld with content as in Example 1

node 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);
    });

More Details

See https://github.com/eclipse-thingweb/node-wot/

0.8.13

1 month ago

0.8.12

4 months ago

0.8.11

5 months ago

0.8.9

7 months ago

0.8.8

8 months ago

0.8.10

6 months ago

0.8.7

11 months ago

0.8.6

1 year ago

0.8.5

1 year ago

0.8.4

1 year ago

0.8.3

1 year ago

0.8.2

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.7.8

3 years ago

0.7.7

3 years ago

0.7.6

3 years ago

0.7.5

3 years ago

0.7.4

3 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.7.0-SNAPSHOT.6

4 years ago

0.7.0-SNAPSHOT.5

4 years ago

0.7.0-SNAPSHOT.4

4 years ago

0.7.0-SNAPSHOT.3

5 years ago

0.7.0-SNAPSHOT.2

5 years ago

0.6.3-SNAPSHOT.2

5 years ago

0.7.0-SNAPSHOT.1

5 years ago

0.6.2

5 years ago

0.6.2-SNAPSHOT.1

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.3.0-RC.1

6 years ago