use TransformStream if available

This commit is contained in:
Danny Coates 2018-07-19 14:46:12 -07:00
parent f32ebd913a
commit 38fd349d9b
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
3 changed files with 13 additions and 7 deletions

View File

@ -1,5 +1,5 @@
import 'buffer'; import 'buffer';
import { transform } from './streams'; import { transformStream } from './streams';
const NONCE_LENGTH = 12; const NONCE_LENGTH = 12;
const TAG_LENGTH = 16; const TAG_LENGTH = 16;
@ -353,9 +353,12 @@ export default class ECE {
new BlobSlicer(this.input, this.rs, this.mode) new BlobSlicer(this.input, this.rs, this.mode)
); );
} else { } else {
inputStream = transform(this.input, new StreamSlicer(this.rs, this.mode)); inputStream = transformStream(
this.input,
new StreamSlicer(this.rs, this.mode)
);
} }
return transform( return transformStream(
inputStream, inputStream,
new ECETransformer(this.mode, this.key, this.rs, this.salt) new ECETransformer(this.mode, this.key, this.rs, this.salt)
); );

View File

@ -1,6 +1,6 @@
import Keychain from './keychain'; import Keychain from './keychain';
import { downloadStream } from './api'; import { downloadStream } from './api';
import { transform } from './streams'; import { transformStream } from './streams';
import contentDisposition from 'content-disposition'; import contentDisposition from 'content-disposition';
let noSave = false; let noSave = false;
@ -24,7 +24,7 @@ async function decryptStream(request) {
const body = await file.download.result; const body = await file.download.result;
const readStream = transform(body, { const readStream = transformStream(body, {
transform: (chunk, controller) => { transform: (chunk, controller) => {
file.progress += chunk.length; file.progress += chunk.length;
controller.enqueue(chunk); controller.enqueue(chunk);

View File

@ -1,6 +1,9 @@
/* global ReadableStream */ /* global ReadableStream TransformStream */
export function transform(readable, transformer) { export function transformStream(readable, transformer) {
if (typeof TransformStream === 'function') {
return readable.pipeThrough(new TransformStream(transformer));
}
const reader = readable.getReader(); const reader = readable.getReader();
const tstream = new ReadableStream({ const tstream = new ReadableStream({
start(controller) { start(controller) {