WIP on shimming streams in firefox

This commit is contained in:
Danny Coates 2018-07-13 17:05:19 -07:00
parent 23c347175a
commit f4f8332f96
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
5 changed files with 46 additions and 11 deletions

View file

@ -1,4 +1,12 @@
require('buffer');
import 'buffer';
import TransformStream from './transformStream';
import { ReadableStream as ReadableStreamPony } from 'web-streams-ponyfill';
try {
new ReadableStream().pipeThrough(new TransformStream());
} catch (e) {
// eslint-disable-next-line no-global-assign
ReadableStream = ReadableStreamPony;
}
const NONCE_LENGTH = 12;
const TAG_LENGTH = 16;
@ -316,7 +324,7 @@ class StreamSlicer {
/*
input: a blob or a ReadableStream containing data to be transformed
key: Uint8Array containing key of size KEY_LENGTH
key: Uint8Array containing key of size KEY_LENGTH
mode: string, either 'encrypt' or 'decrypt'
rs: int containing record size, optional
salt: ArrayBuffer containing salt of KEY_LENGTH length, optional

View file

@ -1,5 +1,6 @@
import Keychain from './keychain';
import { downloadStream } from './api';
import TransformStream from './transformStream';
let noSave = false;
const map = new Map();
@ -37,8 +38,8 @@ async function decryptStream(request) {
'Content-Type': file.type,
'Content-Length': file.size
};
return new Response(decrypted, { headers });
const body = decrypted.local ? decrypted.nativeReadable : decrypted;
return new Response(body, { headers });
} catch (e) {
if (noSave) {
return new Response(null, { status: e.message });

25
app/transformStream.js Normal file
View file

@ -0,0 +1,25 @@
/* global TransformStream */
import { createReadableStreamWrapper } from '@mattiasbuelens/web-streams-adapter';
import { TransformStream as TransformStreamPony } from 'web-streams-ponyfill';
const toNative = createReadableStreamWrapper(ReadableStream);
class TransformStreamLocal {
constructor(transformer) {
this.stream = new TransformStreamPony(transformer);
this.local = true;
}
get nativeReadable() {
return toNative(this.stream.readable);
}
get readable() {
return this.stream.readable;
}
get writable() {
return this.stream.writable;
}
}
export default (typeof TransformStream === 'function'
? TransformStream
: TransformStreamLocal);