classFileStreamextendsStream{constructor(src,type="text"){super((resolve,reject)=>{constxhr=newXMLHttpRequest();xhr.onreadystatechange=()=>{if(xhr.readyState===4){if((200<=xhr.status&&xhr.status<300)||(xhr.status===304)){constsource=xhr.response;resolve(source);}else{reject(newError(`File not found. ${url}`));}}};xhr.onerror=()=>{reject(newError(`File not found. ${url}`));};xhr.open("GET",src,true);xhr.responseType=type;xhr.send(null);});}}
how to use pipe class.
classToImagePipeextendsPipe{constructor(){super((data,resolve,reject)=>{constsource=newImage();source.onload=()=>resolve(source);source.onerror=()=>reject(newError("Can not process image."));switch(true){casetypeof(data.source)==="string":
source.src=`data:image/jpeg;base64,${data.source}`;break;casedata.sourceinstanceofBlob:
source.src=window.URL.createObjectURL(data.source);break;casedata.sourceinstanceofArrayBuffer:
constbytes=newUint8Array(data.source);letbinaryData="";for(leti=0,len=bytes.byteLength;i<len;i++){binaryData+=String.fromCharCode(bytes[i]);}source.src=`data:image/jpeg;base64,${window.btoa(binaryData)}`;break;}});}}