我正在尝试编写一个 React JS 代码,该代码将下载 gzip - 每天从服务器一次的文件,如果该文件今天已经下载 - 使用下载的文件。
下载文件的代码非常简单,并且可以正常工作。
import FileSaver from 'file-saver'
const today = () => (new Date().toISOString().slice(0, 10))
const schedules = () => concat(
...config.epgUrls.map(
(url) =>
ajax({
url,
method: 'GET',
responseType: 'blob'
})
)
)
export const saveChannelsEpic =
(action$) =>
action$.pipe(
ofType(SAVE_CHANNELS),
mergeMap(
() =>
schedules()
.pipe(
pluck('response'),
map((gzipped) => FileSaver.saveAs(gzipped, `${today()}.gz`)),
map(() => saveChannelsFulfilled()),
catchError((err) => {
console.table(err.message)
saveChannelsFailed(err.message)
return EMPTY
})
)
)
)
当我想从文件系统(实际上是从浏览器的下载文件夹)中读取它时,问题就开始了。有人可以建议吗?我知道浏览器只能访问文件系统,但是有什么解决方法吗?我的意思是访问 'file://C:/Users/MyUser/Downloads/*.gz' 或类似的东西。
ps 我很乐意将文件存储在 localStorage 中,但似乎有一个限制 ~ 8 MB。我的文件解压后约为 100MB,gzip 压缩后约为 20MB。