forked from floraachy/ImageKnife
1.新增支持file://类型scheme的图库文件显示能力
Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
parent
e963f82a02
commit
d043745098
|
@ -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 {
|
||||
// 网络下载
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue