Don't mutate prototypes of Uint8Array, ReadableStream and ReadableStreamDefaultWriter

This commit is contained in:
Daniel Huigens
2018-05-15 18:56:25 +02:00
parent 70f0e1d2f5
commit 4ada3fa590
13 changed files with 145 additions and 121 deletions

View File

@@ -9,7 +9,7 @@ const input = require('./testInputs.js');
function stringify(array) {
if (openpgp.util.isStream(array)) {
return array.readToEnd().then(stringify);
return openpgp.stream.readToEnd(array).then(stringify);
}
if (!openpgp.util.isUint8Array(array)) {

View File

@@ -21,7 +21,7 @@ describe('Streaming', function() {
data,
passwords: ['test'],
});
const msgAsciiArmored = util.Uint8Array_to_str(await encrypted.data.readToEnd());
const msgAsciiArmored = util.Uint8Array_to_str(await openpgp.stream.readToEnd(encrypted.data));
const message = await openpgp.message.readArmored(msgAsciiArmored);
const decrypted = await openpgp.decrypt({
passwords: ['test'],
@@ -48,7 +48,7 @@ describe('Streaming', function() {
data,
passwords: ['test'],
});
const msgAsciiArmored = util.Uint8Array_to_str(await encrypted.data.readToEnd());
const msgAsciiArmored = util.Uint8Array_to_str(await openpgp.stream.readToEnd(encrypted.data));
const message = await openpgp.message.readArmored(msgAsciiArmored);
const decrypted = await openpgp.decrypt({
passwords: ['test'],
@@ -85,6 +85,6 @@ describe('Streaming', function() {
format: 'binary'
});
expect(util.isStream(decrypted.data)).to.be.true;
expect(await decrypted.data.readToEnd()).to.deep.equal(util.concatUint8Array(plaintext));
expect(await openpgp.stream.readToEnd(decrypted.data)).to.deep.equal(util.concatUint8Array(plaintext));
});
});