wormhole-crypto
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -47,8 +47,32 @@ /* eslint-env browser */ | ||
this.reader = readable.getReader() | ||
this.progressMade = false // reset on each pull | ||
this.wrappedController = null | ||
} | ||
async start (controller) { | ||
this.wrappedController = { | ||
enqueue: (value) => { | ||
this.progressMade = true | ||
controller.enqueue(value) | ||
}, | ||
error: (reason) => { | ||
this.progressMade = true | ||
if (!(reason instanceof Error)) { | ||
reason = new Error(`stream errored; reason: ${reason}`) | ||
} | ||
controller.error(reason) | ||
this.reader.cancel(reason).catch(() => {}) | ||
this.rejectDone(reason) | ||
}, | ||
terminate: () => { | ||
this.progressMade = true | ||
controller.close() | ||
this.reader.cancel(new Error('stream terminated')).catch(() => {}) | ||
this.resolveDone() | ||
} | ||
} | ||
if (this.transformer.start) { | ||
try { | ||
await this.transformer.start(controller) | ||
await this.transformer.start(this.wrappedController) | ||
} catch (err) { | ||
@@ -62,12 +86,5 @@ this.rejectDone(err) | ||
async pull (controller) { | ||
let enqueued = false | ||
const wrappedController = { | ||
enqueue (d) { | ||
enqueued = true | ||
controller.enqueue(d) | ||
} | ||
} | ||
this.progressMade = false | ||
// eslint-disable-next-line no-unmodified-loop-condition | ||
while (!enqueued) { | ||
while (!this.progressMade) { | ||
try { | ||
@@ -77,3 +94,3 @@ const data = await this.reader.read() | ||
if (this.transformer.flush) { | ||
await this.transformer.flush(controller) | ||
await this.transformer.flush(this.wrappedController) | ||
} | ||
@@ -85,8 +102,9 @@ controller.close() | ||
if (this.transformer.transform) { | ||
await this.transformer.transform(data.value, wrappedController) | ||
await this.transformer.transform(data.value, this.wrappedController) | ||
} else { | ||
wrappedController.enqueue(data.value) | ||
this.wrappedController.enqueue(data.value) | ||
} | ||
} catch (err) { | ||
this.rejectDone(err) | ||
this.reader.cancel(err).catch(() => {}) | ||
throw err | ||
@@ -93,0 +111,0 @@ } |
{ | ||
"name": "wormhole-crypto", | ||
"description": "Streaming encryption for Wormhole.app, based on Encrypted Content-Encoding for HTTP (RFC 8188)", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Socket Inc", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
36185
812
0