TransformStream transformer cancel() method
Limited availability
The cancel() method of a TransformStream transformer cleans up resources when the readable side cancels or the writable side aborts.
Browser support
Need this feature?
Leave a 👍 on the feedback issue
Don't forget to also leave a comment explaining your specific use case.
MDN documentation
No MDN documentation found. You can search for the feature on MDN. If you believe that MDN has no documentation about this feature, you can open an issue on MDN's GitHub repository.Specifications
- Streams (#dom-transformer-cancel), from Streams Workstream (WHATWG).
Web Platform Tests (WPT)
View the latest WPT test results for this featureDeveloper use cases
-
I use a `TransformStream` for encrypting large amounts of data in a streaming fashion. Because I need to support funky ECC curves (Brainpool) and authenticated encryption (AES-GCM) to adhere to regulatory guidelines, the encryption is performed using OpenSSL via WASM. To encrypt data, the `start` method of the transformer instantiates a new instance of the encryptor class implemented in C++ using Emscriptens Javascript glue code. Without a `cancel` callback method, the encryptor instance leaves behind a memory leak filling up the WASM heap until no more memory can be allocated. The encryption is only one step of a whole pipeline: * Compression using zip.js (readable stream) * SHA512 hashing of the unencrypted ZIP using hash-wasm (transform stream) * encryption using OpenSSL over WASM (transform stream) * SHA512 hashing of the encrypted ZIP using hash-wasm (transform stream) * writing to OPFS (writable stream) Since this process can be aborted by the user to make changes to the input files and the encryption transformer passes whole chunks to WASM, cancelling the stream pipeline multiple times in a row can leak a lot of memory pretty fast.
I use a `TransformStream` for encrypting large amounts of data in a streaming fashion. Because I need to support funky ECC curves (Brainpool) and authenticated encryption (AES-GCM) to adhere to regulatory guidelines, the encryption is performed using OpenSSL via WASM. To encrypt data, the `start` method of the transformer instantiates a new instance of the encryptor class implemented in C++ using Emscriptens Javascript glue code. Without a `cancel` callback method, the encryptor instance leaves behind a memory leak filling up the WASM heap until no more memory can be allocated. The encryption is only one step of a whole pipeline: * Compression using zip.js (readable stream) * SHA512 hashing of the unencrypted ZIP using hash-wasm (transform stream) * encryption using OpenSSL over WASM (transform stream) * SHA512 hashing of the encrypted ZIP using hash-wasm (transform stream) * writing to OPFS (writable stream) Since this process can be aborted by the user to make changes to the input files and the encryption transformer passes whole chunks to WASM, cancelling the stream pipeline multiple times in a row can leak a lot of memory pretty fast. [see original comment]
View as JSON | Edit this feature | Report an issue | Web-features entry: source, dist