master分支合并taskpool分支代码

Signed-off-by: zenggaofeng <zenggaofeng2@h-partners.com>
This commit is contained in:
zenggaofeng 2024-03-22 10:42:24 +08:00
parent a3ce29f8d2
commit 598b3eaf58
6 changed files with 23 additions and 18 deletions

View File

@ -109,13 +109,18 @@ struct basicTestFileIOPage {
this.imageHint2 = 'appFilePath未取到值,请按顺序从上往下,从左往右依次测试'
return
}
let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif';
let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif';
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder1')
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2')
FileUtils.getInstance().copyFile(filePath1, filePath2);
this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif'
console.log('Folder2 imaeFile =' + this.imageFile)
try {
let filePath1 = this.appFilePath + '/Folder1/jpgSample.gif';
let filePath2 = this.appFilePath + '/Folder2/jpgSample.gif';
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder1')
FileUtils.getInstance().createFolder(this.appFilePath + '/Folder2')
FileUtils.getInstance().copyFile(filePath1, filePath2);
this.imageFile = 'file://' + this.appFilePath + '/Folder2/jpgSample.gif'
console.log('Folder2 imaeFile =' + this.imageFile)
} catch (e) {
console.log('appFilePath未取到值,请按顺序从上往下,从左往右依次测试:'+JSON.stringify(e))
}
})
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button('显示空PixelMap')

View File

@ -19,7 +19,7 @@ import { FileReader } from './FileReader'
import { DiskCacheEntry } from './DiskCacheEntry'
import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5'
import { Context } from '@ohos.abilityAccessCtrl'
import { common } from '@kit.AbilityKit'
import common from '@ohos.app.ability.common'
export class DiskLruCache {
// 默认缓存数据最大值

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fs, { ReadOptions } from '@ohos.file.fs';
import fs from '@ohos.file.fs';
import { RequestOption } from '../imageknife/RequestOption';
export class FileReader {

View File

@ -39,8 +39,8 @@ import { MethodMutex } from './utils/base/MethodMutex'
import worker from '@ohos.worker'
import common from '@ohos.app.ability.common'
import { MemoryLruCache } from '../cache/MemoryLruCache'
import { BusinessError } from '@kit.BasicServicesKit'
import { taskpool } from '@kit.ArkTS'
import { BusinessError } from '@ohos.base'
import taskpool from '@ohos.taskpool'
import { GIFFrame } from './utils/gif/GIFFrame'
import emitter from '@ohos.events.emitter';
@ -588,16 +588,16 @@ export class ImageKnife {
retryholderSrc: request.retryholderSrc,
});
//使用taskpool多线程执行资源下载
let task = new taskpool.Task(taskExecute, taskParams, loadSrcJson)
let task:ESObject = new taskpool.Task(taskExecute, taskParams, loadSrcJson)
task.setTransferList([])
emitter.on(Constants.PROGRESS_EMITTER, (data) => {
emitter.on(Constants.PROGRESS_EMITTER as ESObject, (data:ESObject) => {
if (request.progressFunc && data?.data?.value) {
let percent = data.data.value as number;
request.progressFunc.asyncSuccess(percent);
}
});
taskpool.execute(task).then((data) => {
taskpool.execute(task).then((data: ESObject) => {
if (usageType == Constants.PLACE_HOLDER) {
if ((typeof (data as PixelMap).isEditable) == 'boolean') {
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, data as PixelMap);
@ -718,7 +718,7 @@ async function taskExecute(taskParams: TaskParams, loadSrcJson: string): Promise
"value": percentValue,
}
};
emitter.emit(Constants.PROGRESS_EMITTER, eventData)
emitter.emit(Constants.PROGRESS_EMITTER as ESObject, eventData)
}
let transformations = taskParams.transformations;

View File

@ -56,7 +56,7 @@ import common from '@ohos.app.ability.common'
import { GIFFrame } from './utils/gif/GIFFrame'
import { MemoryCacheProxy } from './requestmanage/MemoryCacheProxy'
import { DiskCacheProxy } from './requestmanage/DiskCacheProxy'
import { DiskLruCache } from '../cache/disklrucache'
import { DiskLruCache } from '../cache/DiskLruCache'
import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5'
import { FileUtils } from '../cache/FileUtils'

View File

@ -14,7 +14,7 @@
*/
import { ICache } from "../requestmanage/ICache"
import { DiskLruCache } from "../../cache/disklrucache"
import { DiskLruCache } from "../../cache/DiskLruCache"
export class DiskCacheProxy implements ICache<string, ArrayBuffer> {
private mDiskLruCache: DiskLruCache;
@ -29,7 +29,7 @@ export class DiskCacheProxy implements ICache<string, ArrayBuffer> {
}
getCachePath():string{
let folderPath = this.mDiskLruCache.getPath();
let folderPath:string = this.mDiskLruCache.getPath();
if (folderPath.endsWith('/')) {
return folderPath;
} else {