/*! OpenPGP.js v5.8.0 - 2023-08-14 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */ "undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};function e(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+r+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}function r(t){if(!t)throw new TypeError("Assertion failed")}function n(){}function i(t){return"object"==typeof t&&null!==t||"function"==typeof t}function o(t){if("function"!=typeof t)return!1;var e=!1;try{new t({start:function(){e=!0}})}catch(t){}return e}function a(t){return!!i(t)&&"function"==typeof t.getReader}function s(t){return!!i(t)&&"function"==typeof t.getWriter}function u(t){return!!i(t)&&(!!a(t.readable)&&!!s(t.writable))}function d(t){try{return t.getReader({mode:"byob"}).releaseLock(),!0}catch(t){return!1}}function h(t){r(function(t){return!!o(t)&&!!a(new t)}(t));var e=function(t){try{return new t({type:"bytes"}),!0}catch(t){return!1}}(t);return function(r,n){var i=(void 0===n?{}:n).type;if("bytes"!==(i=f(i))||e||(i=void 0),r.constructor===t&&("bytes"!==i||d(r)))return r;if("bytes"===i){var o=c(r,{type:i});return new t(o)}o=c(r);return new t(o)}}function c(t,e){var n=(void 0===e?{}:e).type;return r(a(t)),r(!1===t.locked),"bytes"===(n=f(n))?new y(t):new _(t)}function f(t){var e=t+"";if("bytes"===e)return e;if(void 0===t)return t;throw new RangeError("Invalid type is specified")}var l=function(){function t(t){this._underlyingReader=void 0,this._readerMode=void 0,this._readableStreamController=void 0,this._pendingRead=void 0,this._underlyingStream=t,this._attachDefaultReader()}return t.prototype.start=function(t){this._readableStreamController=t},t.prototype.cancel=function(t){return r(void 0!==this._underlyingReader),this._underlyingReader.cancel(t)},t.prototype._attachDefaultReader=function(){if("default"!==this._readerMode){this._detachReader();var t=this._underlyingStream.getReader();this._readerMode="default",this._attachReader(t)}},t.prototype._attachReader=function(t){var e=this;r(void 0===this._underlyingReader),this._underlyingReader=t;var i=this._underlyingReader.closed;i&&i.then((function(){return e._finishPendingRead()})).then((function(){t===e._underlyingReader&&e._readableStreamController.close()}),(function(r){t===e._underlyingReader&&e._readableStreamController.error(r)})).catch(n)},t.prototype._detachReader=function(){void 0!==this._underlyingReader&&(this._underlyingReader.releaseLock(),this._underlyingReader=void 0,this._readerMode=void 0)},t.prototype._pullWithDefaultReader=function(){var t=this;this._attachDefaultReader();var e=this._underlyingReader.read().then((function(e){var r=t._readableStreamController;e.done?t._tryClose():r.enqueue(e.value)}));return this._setPendingRead(e),e},t.prototype._tryClose=function(){try{this._readableStreamController.close()}catch(t){}},t.prototype._setPendingRead=function(t){var e,r=this,n=function(){r._pendingRead===e&&(r._pendingRead=void 0)};this._pendingRead=e=t.then(n,n)},t.prototype._finishPendingRead=function(){var t=this;if(this._pendingRead){var e=function(){return t._finishPendingRead()};return this._pendingRead.then(e,e)}},t}(),_=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return e(r,t),r.prototype.pull=function(){return this._pullWithDefaultReader()},r}(l);function p(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}var y=function(t){function n(e){var r=this,n=d(e);return(r=t.call(this,e)||this)._supportsByob=n,r}return e(n,t),Object.defineProperty(n.prototype,"type",{get:function(){return"bytes"},enumerable:!1,configurable:!0}),n.prototype._attachByobReader=function(){if("byob"!==this._readerMode){r(this._supportsByob),this._detachReader();var t=this._underlyingStream.getReader({mode:"byob"});this._readerMode="byob",this._attachReader(t)}},n.prototype.pull=function(){if(this._supportsByob){var t=this._readableStreamController.byobRequest;if(t)return this._pullWithByobRequest(t)}return this._pullWithDefaultReader()},n.prototype._pullWithByobRequest=function(t){var e=this;this._attachByobReader();var r=new Uint8Array(t.view.byteLength),n=this._underlyingReader.read(r).then((function(r){var n,i,o;e._readableStreamController,r.done?(e._tryClose(),t.respond(0)):(n=r.value,i=t.view,o=p(n),p(i).set(o,0),t.respond(r.value.byteLength))}));return this._setPendingRead(n),n},n}(l);function v(t){return r(function(t){return!!o(t)&&!!s(new t)}(t)),function(e){if(e.constructor===t)return e;var r=g(e);return new t(r)}}function g(t){r(s(t)),r(!1===t.locked);var e=t.getWriter();return new b(e)}var b=function(){function t(t){var e=this;this._writableStreamController=void 0,this._pendingWrite=void 0,this._state="writable",this._storedError=void 0,this._underlyingWriter=t,this._errorPromise=new Promise((function(t,r){e._errorPromiseReject=r})),this._errorPromise.catch(n)}return t.prototype.start=function(t){var e=this;this._writableStreamController=t,this._underlyingWriter.closed.then((function(){e._state="closed"})).catch((function(t){return e._finishErroring(t)}))},t.prototype.write=function(t){var e=this,r=this._underlyingWriter;if(null===r.desiredSize)return r.ready;var n=r.write(t);n.catch((function(t){return e._finishErroring(t)})),r.ready.catch((function(t){return e._startErroring(t)}));var i=Promise.race([n,this._errorPromise]);return this._setPendingWrite(i),i},t.prototype.close=function(){var t=this;return void 0===this._pendingWrite?this._underlyingWriter.close():this._finishPendingWrite().then((function(){return t.close()}))},t.prototype.abort=function(t){if("errored"!==this._state)return this._underlyingWriter.abort(t)},t.prototype._setPendingWrite=function(t){var e,r=this,n=function(){r._pendingWrite===e&&(r._pendingWrite=void 0)};this._pendingWrite=e=t.then(n,n)},t.prototype._finishPendingWrite=function(){var t=this;if(void 0===this._pendingWrite)return Promise.resolve();var e=function(){return t._finishPendingWrite()};return this._pendingWrite.then(e,e)},t.prototype._startErroring=function(t){var e=this;if("writable"===this._state){this._state="erroring",this._storedError=t;var r=function(){return e._finishErroring(t)};void 0===this._pendingWrite?r():this._finishPendingWrite().then(r,r),this._writableStreamController.error(t)}},t.prototype._finishErroring=function(t){"writable"===this._state&&this._startErroring(t),"erroring"===this._state&&(this._state="errored",this._errorPromiseReject(this._storedError))},t}();function R(t){return r(function(t){return!!o(t)&&!!u(new t)}(t)),function(e){if(e.constructor===t)return e;var r=w(e);return new t(r)}}function w(t){r(u(t));var e=t.readable,n=t.writable;r(!1===e.locked),r(!1===n.locked);var i,o=e.getReader();try{i=n.getWriter()}catch(t){throw o.releaseLock(),t}return new m(o,i)}var m=function(){function t(t,e){var r=this;this._transformStreamController=void 0,this._onRead=function(t){if(!t.done)return r._transformStreamController.enqueue(t.value),r._reader.read().then(r._onRead)},this._onError=function(t){r._flushReject(t),r._transformStreamController.error(t),r._reader.cancel(t).catch(n),r._writer.abort(t).catch(n)},this._onTerminate=function(){r._flushResolve(),r._transformStreamController.terminate();var t=new TypeError("TransformStream terminated");r._writer.abort(t).catch(n)},this._reader=t,this._writer=e,this._flushPromise=new Promise((function(t,e){r._flushResolve=t,r._flushReject=e}))}return t.prototype.start=function(t){this._transformStreamController=t,this._reader.read().then(this._onRead).then(this._onTerminate,this._onError);var e=this._reader.closed;e&&e.then(this._onTerminate,this._onError)},t.prototype.transform=function(t){return this._writer.write(t)},t.prototype.flush=function(){var t=this;return this._writer.close().then((function(){return t._flushPromise}))},t}();export{h as createReadableStreamWrapper,R as createTransformStreamWrapper,c as createWrappingReadableSource,w as createWrappingTransformer,g as createWrappingWritableSink,v as createWritableStreamWrapper}; //# sourceMappingURL=web-streams-adapter.min.mjs.map