You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
;(file=>{constfr=newFileReader()fr.onload=()=>{console.log('FileReader.readAsText()',fr.result)}fr.readAsText(file)})(newFile(['hello from fisker.txt'],'fisker.txt'))
使用 Response 则优雅很多
;(asyncfile=>{console.log('Response.text()',awaitnewResponse(file).text())})(newFile(['hello from fisker.txt'],'fisker.txt'))
Response: https://developer.mozilla.org/en-US/docs/Web/API/Response
FileReader: https://developer.mozilla.org/en-US/docs/Web/API/FileReader
Response是Promise的,而FileReader是基于事件的
同样读取一个文件
使用 FileReader
使用 Response 则优雅很多
不过两者的api有很大不同,有些api没有对应的方法
FileReader.readAsArrayBuffer() -> Body.arrayBuffer()
FileReader.readAsBinaryString() -> 无
FileReader.readAsDataURL() -> 无
FileReader.readAsText() -> Body.text()
不过也不是很难实现
readAsBinaryString
readAsDataURL
The text was updated successfully, but these errors were encountered: