不懂就问, Blob 类型,怎么通过 fileBinary 属性转化成 ArrayBuffer 的?
最近在修一个 legacy bug,看到一段不太懂的代码。
调用的是 dropbox 的 api (参考这个链接) https://www.dropbox.com/developers/documentation/http/documentation#files-download
这里的 dropbox 的文档就有点问题。该 API 的返回值,其实包含一个 property named fileBlob,类型是 Blob (在文档里面没有写出来)
我们就是通过这个 fileBlob 拿到下载文件的内容。
我们代码大约是:
async get(fileId: string): Promise<ArrayBuffer> { “blabla...” const fileData = await [dropbox SDK client API call] return (fileData as any).fileBinary; }
成功返回了。内容也都拿到了。但是,这里,我不理解的是, fileData 的类型是 dropbox.files.FileMetadata, 这个里面只有 property – fileBlob,类型是 Blob,没有 fileBinary 啊?这是怎么通过(fileData as any).fileBinary 转化成 ArrayBuffer 的?
更骚的是, 外面的调用者,直接通过下面这段来判断文件大小,也是成功的。
const fileData = await get("fileid"); (fileData as Buffer).length
google 了一些 ArrayBuffer, Blob, and Buffer 的相关资料,也没发现能够这样转换啊?
特来请教一下。有没有老司机 /大神解惑一下。
谢谢!