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AjC,EAAuC;AACrC,4BAAM,OAAN,GAAgB,IAAhB;AACA,6BAAO,KAAP;AACD,qBAHD,MAGO;AACL,4BAAM,OAAN,GAAgB,IAAhB;AACA,4BAAM,QAAN,IAAkB,KAAK,MAAvB;AACA,8BAAQ,IAAR;AACD;AACF,mBATD;AAUD,iBAXM,C;;;;;;;;;;;;;;;;;;wBA7BO;AAChB,aAAO,CAAC,KAAK,MAAL,CAAY,QAApB;AACD","file":"virtual-buffer.js","sourcesContent":["'use strict'\n\nimport {Slicer} from 'pipette'\n\nconst chunkSize = 1024 * 1024\n\nexport class VirtualBuffer {\n constructor (readStream) {\n this.slicer = new Slicer(readStream)\n this.position = 0\n this.promise = null\n }\n\n get isDepleted () {\n return !this.slicer.readable\n }\n\n // length = -1 means 'until the end'\n async readChunk (length, label) {\n const _this = this\n if (this.promise !== null) {\n throw new Error('pomise already there !!!', this.promise)\n }\n if (length === -1) {\n const chunks = []\n let error = false\n do {\n const res = await new Promise((resolve, reject) => {\n this.slicer.read(chunkSize, (error, length, data, offset) => {\n if (error !== false && error !== true) {\n reject(error)\n } else {\n resolve({error, data})\n }\n })\n })\n error = res.error\n chunks.push(res.data)\n } while (error === false)\n return Buffer.concat(chunks)\n } else {\n this.promise = label\n return new Promise((resolve, reject) => {\n this.slicer.read(length, (error, actualLength, data, offset) => {\n if (error !== false && error !== true) {\n _this.promise = null\n reject(error)\n } else {\n _this.promise = null\n _this.position += data.length\n resolve(data)\n }\n })\n })\n }\n }\n}\n"]}
\No newline at end of file