1.新增支持file://类型scheme的图库文件显示能力

Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
zhoulisheng1 2023-05-24 11:01:05 +08:00
parent e963f82a02
commit d043745098
2 changed files with 11 additions and 8 deletions

View File

@ -32,7 +32,7 @@ export class DownloadClient implements IDataFetch {
.filesDir) || request.loadSrc.startsWith(globalThis.ImageKnife.getImageKnifeContext().cacheDir)) {
// 本地沙盒
this.localFileClient.loadData(request, onCompleteFunction, onErrorFunction)
} else if (request.loadSrc.startsWith('datashare://')) {
} else if (request.loadSrc.startsWith('datashare://') || request.loadSrc.startsWith('file://')) {
this.dataShareFileClient.loadData(request, onCompleteFunction, onErrorFunction)
} else {
// 网络下载

View File

@ -21,16 +21,19 @@ export class LoadDataShareFileClient implements IDataFetch {
loadData(request: RequestOption, onComplete: (img: ArrayBuffer) => void, onError: (err: string) => void) {
if (typeof request.loadSrc == 'string') {
fs.open(request.loadSrc, fs.OpenMode.READ_ONLY).then((file) => {
let stat = fs.statSync(file.fd);
let buf = new ArrayBuffer(stat.size);
fs.read(file.fd, buf).then((readLen) => {
onComplete(buf);
fs.close(file.fd);
fs.stat(file.fd).then(stat =>{
let buf = new ArrayBuffer(stat.size);
fs.read(file.fd, buf).then((readLen) => {
onComplete(buf);
fs.close(file.fd);
}).catch(err => {
onError('LoadDataShareFileClient fs.read err happend uri=' + request.loadSrc + " err.msg=" + err?.message + " err.code=" + err?.code)
})
}).catch(err => {
onError('LoadDataShareFileClient fs.read err happend uri=' + request.loadSrc + " err.msg=" + err.message + " err.code=" + err.code)
onError('LoadDataShareFileClient fs.stat err happend uri=' + request.loadSrc + " err.msg=" + err?.message + " err.code=" + err?.code)
})
}).catch(err => {
onError('LoadDataShareFileClient fs.open err happend uri=' + request.loadSrc + " err.msg=" + err.message + " err.code=" + err.code)
onError('LoadDataShareFileClient fs.open err happend uri=' + request.loadSrc + " err.msg=" + err?.message + " err.code=" + err?.code)
})
}
}