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;

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);

11
package-lock.json generated
View File

@ -91,7 +91,8 @@
"@mattiasbuelens/web-streams-adapter": {
"version": "0.1.0-alpha.1",
"resolved": "https://registry.npmjs.org/@mattiasbuelens/web-streams-adapter/-/web-streams-adapter-0.1.0-alpha.1.tgz",
"integrity": "sha512-8YK2ZY6CAgrzFGfW2uPyNDMYvh7OmWjrlbdP+GeHiMJhzPF3XwrQaHyLQ4IZqGTj8NW879ttfbcqbLqQxWvtsw=="
"integrity": "sha512-8YK2ZY6CAgrzFGfW2uPyNDMYvh7OmWjrlbdP+GeHiMJhzPF3XwrQaHyLQ4IZqGTj8NW879ttfbcqbLqQxWvtsw==",
"dev": true
},
"@mrmlnc/readdir-enhanced": {
"version": "2.2.1",
@ -16276,10 +16277,10 @@
"minimalistic-assert": "1.0.1"
}
},
"web-streams-polyfill": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-1.3.2.tgz",
"integrity": "sha1-NxkkXpCSgtk5Z4JfRLzVUOnAOZU=",
"web-streams-ponyfill": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/web-streams-ponyfill/-/web-streams-ponyfill-1.4.2.tgz",
"integrity": "sha512-LCHW+fE2UBJ2vjhqJujqmoxh1ytEDEr0dPO3CabMdMDJPKmsaxzS90V1Ar6LtNE5VHLqxR4YMEj1i4lzMAccIA==",
"dev": true
},
"webpack": {

View File

@ -57,6 +57,7 @@
},
"devDependencies": {
"@dannycoates/webpack-dev-server": "^3.1.4",
"@mattiasbuelens/web-streams-adapter": "0.1.0-alpha.1",
"asmcrypto.js": "^0.22.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
@ -112,7 +113,7 @@
"svgo-loader": "^2.1.0",
"testpilot-ga": "^0.3.0",
"val-loader": "^1.1.1",
"web-streams-polyfill": "^1.3.2",
"web-streams-ponyfill": "^1.4.2",
"webpack": "^4.15.1",
"webpack-cli": "^3.0.8",
"webpack-dev-middleware": "^3.1.3",
@ -120,7 +121,6 @@
"webpack-unassert-loader": "^1.2.0"
},
"dependencies": {
"@mattiasbuelens/web-streams-adapter": "0.1.0-alpha.1",
"aws-sdk": "^2.266.1",
"babel-polyfill": "^6.26.0",
"choo": "^6.12.1",