export const blobToFile = (blob, fileName) => {
const file = new File([blob], fileName, {type: blob.type});
return file;
}
export const blobToBase64 = (blob) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = (e) => {
resolve(e.target.result);
};
reader.onerror = () => {
reject();
};
});
};
export const blobToArrayBuffer = (blob) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsArrayBuffer(blob);
reader.onload = (e) => {
resolve(e.target.result);
};
reader.onerror = () => {
reject();
};
});
};
export const blobToBinary = (blob) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsBinaryString(blob);
reader.onload = (e) => {
resolve(e.target.result);
};
reader.onerror = () => {
reject();
};
});
};
export const blobToText = (blob) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsText(blob);
reader.onload = (e) => {
resolve(e.target.result);
};
reader.onerror = () => {
reject();
};
});
};
export const blobToUrl = (blob) => {
const objectUrl = URL.createObjectURL(blob);
return objectUrl;
};
export const fileToBlob = (file) => {
const blob = new Blob([file], {type: file.type})
return blob;
};
export const FileToBase64 = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (e) => {
resolve(e.target.result);
};
reader.onerror = () => {
reject();
};
});
};
export const fileToArrayBuffer = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsArrayBuffer(file);
reader.onload = (e) => {
resolve(e.target.result);
};
reader.onerror = () => {
reject();
};
});
};
export const fileToBinary = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsBinaryString(file);
reader.onload = (e) => {
resolve(e.target.result);
};
reader.onerror = () => {
reject();
};
});
};
export const fileToText = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsText(file);
reader.onload = (e) => {
resolve(e.target.result);
};
reader.onerror = () => {
reject();
};
});
};
export const fileToUrl = (file) => {
const objectUrl = URL.createObjectURL(file);
return objectUrl;
};
export const base64ToBlob = (code) => {
const data = code.split(";base64,");
const contentType = data[0].split(":")[1];
const binary = window.atob(data[1]);
const length = binary.length;
const uInt8Array = new Uint8Array(length);
for (let i = 0; i < length; ++i) {
uInt8Array[i] = binary.charCodeAt(i);
}
return new Blob([uInt8Array], { type: contentType });
};
export const base64ToFile = (code, fileName) => {
const data = code.split(";base64,");
const contentType = data[0].split(":")[1];
const binary = window.atob(data[1]);
const length = binary.length;
const uInt8Array = new Uint8Array(length);
for (let i = 0; i < length; ++i) {
uInt8Array[i] = binary.charCodeAt(i);
}
return new File([uInt8Array], fileName, { type: contentType });
};
export const base64ToArrayBuffer = (code, fileName) => {
const data = code.split(";base64,");
const binary = window.atob(data[1]);
const length = binary.length;
const uInt8Array = new Uint8Array(length);
for (let i = 0; i < length; ++i) {
uInt8Array[i] = binary.charCodeAt(i);
}
return uInt8Array
};
export const base64ToBinary = (code) => {
const data = code.split(";base64,");
const binary = window.atob(data[1]);
return binary
};
export const arrayBufferToBlob = (buffer, type) => {
const blob = new Blob([buffer], {type: type});
return blob;
};
export const arrayBufferToFile = (buffer, fileName, type) => {
const file = new File([buffer], fileName, {type: type});
return file;
};
export const arrayBufferToBase64 = (buffer) => {
const base64 = btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)));
return base64;
};
export const BinaryTobase64 = (binary) => {
const base64 = window.btoa(binary);
return base64
};