FileUtil.readFile接口和file格式图片同步关闭fd

Signed-off-by: zgf <zenggaofeng2@h-partners.com>
This commit is contained in:
zgf 2024-09-27 09:58:27 +08:00
parent 4872cc64f7
commit 6dcf2840b3
4 changed files with 32 additions and 33 deletions

View File

@ -1,3 +1,12 @@
## 3.0.2-rc.0
- FileUtil.readFile接口和file格式图片同步关闭fd
## 3.0.1
- 修复animatorOption属性设置初始化值失效
- 网络请求code为206、204时返回arraybuffer
- ImageKnifeComponent显示非必要文件缓存初始化
- 修复webp静态图无法设置图形变换
## 3.0.1-rc.2
- 修复自定义下载失败无失败回调
- 增加全局配置自定义下载接口

View File

@ -175,7 +175,7 @@ export class ImageKnifeDispatcher {
requestSource: requestSource,
isWatchProgress: isWatchProgress,
memoryKey: memoryKey,
fileCacheFolder: ImageKnife.getInstance().getFileCache().getCacheFolder(),
fileCacheFolder: ImageKnife.getInstance().getFileCache()?.getCacheFolder(),
isAnimator:isAnimator
}
@ -467,7 +467,7 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
});
await promise.then((data: number) => {
if (data == 200) {
if (data == 200 || data == 204 || data == 201 || data == 206) {
resBuf = combineArrayBuffers(arrayBuffers)
} else {
loadError = "HttpDownloadClient has error, http code =" + JSON.stringify(data)
@ -496,7 +496,7 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
let buf = new ArrayBuffer(stat.size);
await fs.read(file.fd, buf).then((readLen) => {
resBuf = buf;
fs.close(file.fd);
fs.closeSync(file.fd);
}).catch((err:BusinessError) => {
loadError = 'LoadDataShareFileClient fs.read err happened uri=' + request.src + " err.msg=" + err?.message + " err.code=" + err?.code;
})
@ -608,19 +608,23 @@ async function requestJob(request: RequestJobRequest, requestList?: List<ImageKn
}
let resPixelmap: PixelMap | undefined = undefined
if (typeValue === 'gif' || typeValue === 'webp') {
let frameCount = await imageSource.getFrameCount()
let size = (await imageSource.getImageInfo()).size
let base64Help = new util.Base64Helper()
if (frameCount == undefined || frameCount == 1) {
} else {
let base64Help = new util.Base64Helper()
let base64str = "data:image/" + typeValue + ";base64," + base64Help.encodeToStringSync(new Uint8Array(resBuf))
LogUtil.log("ImageKnife_DataTime_requestJob_createPixelMap.end_GIF:"+request.src)
LogUtil.log("ImageKnife_DataTime_requestJob.end_GIF:"+request.src)
return {
pixelMap: base64str,
bufferSize: bufferSize,
fileKey: fileKey,
size:size,
type:typeValue
};
let base64str = "data:image/" + typeValue + ";base64," + base64Help.encodeToStringSync(new Uint8Array(resBuf))
LogUtil.log("ImageKnife_DataTime_requestJob_createPixelMap.end_GIF:" + request.src)
LogUtil.log("ImageKnife_DataTime_requestJob.end_GIF:" + request.src)
return {
pixelMap: base64str,
bufferSize: bufferSize,
fileKey: fileKey,
size: size,
type: typeValue
};
}
} else if(typeValue == "svg") {
let hValue = Math.round(request.componentHeight);
let wValue = Math.round(request.componentWidth);

View File

@ -22,12 +22,9 @@ import { ImageKnifeRequestSource } from '../model/ImageKnifeData';
@Component
export struct ImageKnifeAnimatorComponent {
@Watch('watchImageKnifeOption') @ObjectLink imageKnifeOption: ImageKnifeOption;
@Watch('watchAnimatorOption') @State animatorOption: AnimatorOption = new AnimatorOption();
@State animatorOption: AnimatorOption = new AnimatorOption();
@State pixelMap: PixelMap | string | undefined = undefined
@State imageAnimator: Array<ImageFrameInfo> | undefined = undefined
@State state: AnimationStatus = AnimationStatus.Running
@State iterations: number = -1
@State reverse: boolean = false
@State adaptiveWidth: Length = '100%'
@State adaptiveHeight: Length = '100%'
@State objectFit: ImageFit = ImageFit.Contain
@ -64,9 +61,9 @@ export struct ImageKnifeAnimatorComponent {
.width(this.adaptiveWidth)
.height(this.adaptiveHeight)
.border(this.imageKnifeOption.border)
.state(this.state)
.iterations(this.iterations)
.reverse(this.reverse)
.state(this.animatorOption.state == undefined ? AnimationStatus.Running : this.animatorOption.state)
.iterations(this.animatorOption.iterations == undefined ? -1 : this.animatorOption.iterations)
.reverse(this.animatorOption.reverse == undefined ? false : this.animatorOption.reverse)
.onSizeChange((oldValue:SizeOptions, newValue:SizeOptions) => {
this.currentWidth = newValue.width as number
this.currentHeight = newValue.height as number
@ -84,18 +81,6 @@ export struct ImageKnifeAnimatorComponent {
})
}
watchAnimatorOption(){
if(this.animatorOption.state != undefined) {
this.state = this.animatorOption.state
}
if(this.animatorOption.iterations != undefined) {
this.iterations = this.animatorOption.iterations
}
if(this.animatorOption.reverse != undefined) {
this.reverse = this.animatorOption.reverse
}
}
watchImageKnifeOption() {
if (this.request !== undefined) {
this.request.requestState = ImageKnifeRequestState.DESTROY

View File

@ -176,6 +176,7 @@ export class FileUtils {
let length = stat.size;
let buf = new ArrayBuffer(length);
await fs.read(fd, buf);
await fs.close(fd)
return buf
} catch (error) {
let err: BusinessError = error as BusinessError;