PlaintextStream

PlaintextStream

A Readable stream implementation that exposes convenience methods for writing to various locations like files and strings.
 // Run a decrypt, which returns a PlaintextStream.
 plaintextStream = await client.decrypt(decryptParams);

 // PlaintextStream exposes a progress event emitter when toRemoteStore() is called on it.
 plaintextStream.toRemoteStore(fileName);

 plaintextStream.on('progress', progress => {
   console.log(`Uploaded ${progress.loaded} bytes`);
 });

 // Write the plaintext to a local file.
 await stream.toFile("/tmp/plain.txt");
   

Methods

(async) toBuffer() → {Buffer}

Dump the stream content to a buffer. This will consume the stream.
Returns:
- the plaintext in Buffer form.
Type
Buffer

(async) toFile(filepath, encoding)

Dump the stream content to a local file. This will consume the stream.
Parameters:
Name Type Description
filepath string the path of the local file to write plaintext to.
encoding string the charset encoding to use. Defaults to utf-8.

(async) toRemoteStore(fileName, configopt, credentialURLopt) → {RemoteUploadResponse}

Dump the stream content to remote storage. This will consume the stream.
Parameters:
Name Type Attributes Description
fileName string the name of the remote file to write TDF ciphertext to.
config S3ClientConfig <optional>
the object containing remote storage configuration.
A detailed spec for the interface can be found here
credentialURL string <optional>
the url to request remote storage credentials from.
Returns:
- an object containing metadata for the uploaded file.
Type
RemoteUploadResponse

(async) toString(encoding) → {string}

Dump the stream content to a string. This will consume the stream.
Parameters:
Name Type Description
encoding string the charset encoding to use. Defaults to utf-8.
Returns:
- the plaintext in string form.
Type
string