Writer

Writer

Constructor

new Writer()

Source:

Methods

(async) close(cipherOpt, getXorUrl, mimeType) → {Promise.<(Buffer|{name: Buffer, xorUrl: String})>}

Close and commit the ImmutableDataInterface to the network.

Parameters:
Name Type Description
cipherOpt CipherOpt

The cipher method with which to encrypt data

getXorUrl Boolean

(experimental) if the XOR-URL shall also be returned along with the xor address

mimeType String

(experimental) the MIME type to encode in the XOR-URL as the codec of the content

Source:
Example
// Assumes SAFEApp interface has been obtained
const asyncFn = async () => {
    try {
        const cipherOpt = await app.cipherOpt.newPlainText();
        const iDataWriter = await app.immutableData.create()
        const data = 'Most proteins are glycosylated.
        Mass spectrometry methods are used for mapping glycoprotein.';
        await iDataWriter.write(data);
        const iDataAddress = await iDataWriter.close(cipherOpt);

        // Alternatively:
        // const getXorUrl = true;
        // const mimeType = 'text/plain';
        // const iDataMeta = await iDataWriter.close(cipherOpt, getXorUrl, mimeType);
    } catch(err) {
      throw err;
    }
};

write(data) → {Promise}

Append the given data to ImmutableDataInterface. This does not commit data to network.

Parameters:
Name Type Description
data String | Buffer

The string or buffer to write

Source:
Example
// Assumes SAFEApp interface has been obtained
const asyncFn = async () => {
    try {
        const iDataWriter = await app.immutableData.create()
        const data = 'Most proteins are glycosylated.
        Mass spectrometry methods are used for mapping glycoprotein.';
        await iDataWriter.write(data);
    } catch(err) {
      throw err;
    }
};