Skip to content

@pqc-sdk/core / decryptWebStream

Function: decryptWebStream()

decryptWebStream(secretKey): TransformStream<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>

decryptStream as a Web Streams TransformStream. Same incremental-release property as decryptStream applies here too — see its documentation. Piping into a TransformStream does not change that property: bytes written to a downstream sink before the pipe completes are provisional, and the sink must be treated as incomplete until pipeTo's returned promise resolves without rejecting.

Parameters

secretKey

SecretKey<KemAlgorithm>

Returns

TransformStream<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>

Example

ts
import { createReadStream, createWriteStream } from 'node:fs';
import { Readable, Writable } from 'node:stream';
import { pqc } from '@pqc-sdk/core';

// pipeTo's promise rejecting means the sink file holds an incomplete,
// unverified prefix — callers must delete/ignore it on rejection, never
// treat a partially-written output file as done.
await Readable.toWeb(createReadStream('large-file.bin.enc'))
  .pipeThrough(pqc.decryptWebStream(pair.secretKey))
  .pipeTo(Writable.toWeb(createWriteStream('large-file.bin')));