NG
Size: a a a
NG
A
ES
export class File {
/**
* @param {string} encoded
* @returns {number[]}
*/
static convert(encoded) {
const binaryString = window.atob(encoded)
const binaryLen = binaryString.length
const bytes = new Uint8Array(binaryLen)
for (let i = 0; i < binaryLen; i++) {
let ascii = binaryString.charCodeAt(i)
bytes[i] = ascii
}
return bytes
}
/**
* @param {string} name
* @param {number[]} bytes
*/
static save(name, bytes) {
const blob = new Blob([bytes])
// let reader = new FileReader();
// reader.readAsArrayBuffer(blob);
const link = document.createElement("a")
const fileName = name
link.href = window.URL.createObjectURL(blob)
link.download = fileName
link.click()
link.remove()
}
/**
* @param {string} filename
* @param {string} content
*/
static download(filename, content) {
const decoded = this.convert(content)
File.save(filename, decoded)
}
}
NG
NG
ES
NG
NG
ES
fetchIncludedFile = (file, btaDocId) => {
this.setState({ loading: true }, async () => {
const { type, content } = await downloadFile(btaDocId, file.id);
this.setState({ loading: false }, () => {
if (type === 'ok') {
File.download(file.filename, content);
}
});
});
NG
🦜
L
ES
static open(name, bytes) {
const blob = new Blob([bytes])
let reader = new FileReader();
reader.readAsArrayBuffer(blob);
reader.onload = () => {
const link = document.createElement("a")
link.href = window.URL.createObjectURL(reader.result)
}
}
NG
ES
NG
З
З
З
ES