UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 4.82 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import e from"./../../utils/define-nonenumerable-read-only-property.js";import r from"./../../vendor/process.js";import i from"./../../vendor/readable-stream.js";import t from"./../../assert/is-array-like-object.js";import o from"./../../assert/is-error.js";import n from"./../../assert/is-buffer.js";import s from"./../../assert/is-integer.js";import a from"./../../assert/is-nonnegative-integer.js";import m from"./../../utils/copy.js";import p from"./../../utils/inherit.js";import d from"./../../utils/define-nonenumerable-property.js";import u from"./../../buffer/from-string.js";import l from"./../../buffer/ctor.js";import h from"./../../assert/is-plain-object.js";import f from"./../../assert/has-own-property.js";import g from"./../../assert/is-boolean.js";import c from"./../../assert/is-nonnegative-number.js";import b from"./../../assert/is-string.js";import v from"./../../assert/is-function.js";import y from"./../../vendor/debug.js";var j=!1,w=null,_="\n",M={objectMode:j,encoding:w,sep:_},E=h,T=f,O=g.isPrimitive,k=c.isPrimitive,z=b.isPrimitive,x=v;function S(e,r){return E(r)?T(r,"sep")&&(e.sep=r.sep,!z(e.sep))?new TypeError("invalid option. `sep` option must be a primitive string. Option: `"+e.sep+"`."):T(r,"objectMode")&&(e.objectMode=r.objectMode,!O(e.objectMode))?new TypeError("invalid option. `objectMode` option must be a primitive boolean. Option: `"+e.objectMode+"`."):T(r,"encoding")&&(e.encoding=r.encoding,!z(e.encoding)&&null!==e.encoding)?new TypeError("invalid option. `encoding` option must be a primitive string or null. Option: `"+e.encoding+"`."):T(r,"highWaterMark")&&(e.highWaterMark=r.highWaterMark,!k(e.highWaterMark))?new TypeError("invalid option. `highWaterMark` option must be a nonnegative number. Option: `"+e.highWaterMark+"`."):T(r,"serialize")&&(e.serialize=r.serialize,!x(e.serialize))?new TypeError("invalid option. `serialize` option must be a function. Option: `"+e.serialize+"`."):null:new TypeError("invalid argument. Options must be an object. Value: `"+r+"`.")}var V=y,N=V("from-strided-array-stream"),W=i.Readable,P=t,J=o,F=n,C=s.isPrimitive,I=a.isPrimitive,R=m,A=p,B=d,L=e,q=u,D=l,G=M,H=S,K=N;function Q(){var e,r,i;if(!this._destroyed)for(e=!0;e;){if(r=null,this._i+=1,this._i>this._N)return K("Finished iteration."),this.push(null);i=this._buffer[this._idx],K("Value: %s. Idx: %d. Iter: %d.",JSON.stringify(i),this._idx,this._i),this._idx+=this._stride,!1===this._objectMode&&("string"==typeof(i=this._serialize(i))?i=1===this._i?q(i):q(this._sep+i):F(i)?this._i>1&&(i=D.concat([q(this._sep),i])):r=new Error("invalid operation. Serialization function must return a string or Buffer. Value: `"+i+"`.")),r?this.emit("error",r):e=this.push(i)}}function U(e){var i;return this._destroyed?(K("Attempted to destroy an already destroyed stream."),this):(i=this,this._destroyed=!0,r.nextTick((function(){e&&(K("Stream was destroyed due to an error. Error: %s.",J(e)?e.message:JSON.stringify(e)),i.emit("error",e));K("Closing the stream..."),i.emit("close")})),this)}function X(e,r,i,t,o){var n,s,a;if(!(this instanceof X))return arguments.length>4?new X(e,r,i,t,o):new X(e,r,i,t);if(!I(e))throw new TypeError("invalid argument. First argument must be a nonnegative integer. Value: `"+e+"`.");if(!P(r))throw new TypeError("invalid argument. Second argument must be an array-like object. Value: `"+r+"`.");if(!C(i))throw new TypeError("invalid argument. Third argument must be an integer. Value: `"+i+"`.");if(!I(t))throw new TypeError("invalid argument. Fourth argument must be a nonnegative integer. Value: `"+t+"`.");if(e>0&&(a=t+(e-1)*i,t>=r.length||a<0||a>=r.length))throw new RangeError("invalid arguments. Strided array parameters are incompatible with the provided array-like object. Linear index exceeds array bounds.");if(n=R(G),arguments.length>4&&(s=H(n,o)))throw s;return K("Creating a readable stream configured with the following options: %s.",JSON.stringify(n)),W.call(this,n),B(this,"_destroyed",!1),L(this,"_objectMode",n.objectMode),L(this,"_sep",n.sep),L(this,"_serialize",n.serialize||JSON.stringify),L(this,"_buffer",r),L(this,"_N",e),L(this,"_stride",i),L(this,"_offset",t),B(this,"_idx",t),B(this,"_i",0),this}A(X,W),L(X.prototype,"_read",Q),L(X.prototype,"destroy",U);var Y=h,Z=m,$=X;function ee(e,r,i,t,o){var n;if(arguments.length>4){if(!Y(n=o))throw new TypeError("invalid argument. Options must be an object. Value: `"+n+"`.");n=Z(o,1)}else n={};return n.objectMode=!0,new $(e,r,i,t,n)}var re=m,ie=X;function te(e){var r;return r=arguments.length?re(e,1):{},i;function i(e,i,t,o){return new ie(e,i,t,o,r)}}var oe=e,ne=X,se=ee,ae=te;oe(ne,"objectMode",se),oe(ne,"factory",ae);export default ne; //# sourceMappingURL=from-strided-array.js.map