From 173b4d55bd7d69b73cd0344849a804d75759fdeb Mon Sep 17 00:00:00 2001 From: xinhu Date: Thu, 22 Feb 2024 09:53:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=E5=BA=9F=E5=BC=83=E7=9A=84@ohos/filei?= =?UTF-8?q?o=E5=8F=98=E6=9B=B4=E4=B8=BA@ohos.file.fs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xinhu --- AppScope/app.json5 | 2 +- CHANGELOG.md | 3 +++ README-en.md | 24 +++++++++---------- README.md | 16 ++++++------- entry/oh-package.json5 | 2 +- entry/src/main/ets/pages/Index.ets | 4 ++-- .../ets/test/DiskLruCacheTest.test.ets | 14 +++++------ .../test/TestInterfaceResponseTime.test.ets | 2 +- library/oh-package.json5 | 2 +- .../main/ets/components/cache/DiskLruCache.ts | 6 ++--- oh-package.json5 | 2 +- 11 files changed, 40 insertions(+), 37 deletions(-) diff --git a/AppScope/app.json5 b/AppScope/app.json5 index 11868c1..a729026 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -3,7 +3,7 @@ "bundleName": "com.example.disklrucache", "vendor": "example", "versionCode": 1000000, - "versionName": "2.0.2-rc.0", + "versionName": "2.0.2-rc.3", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true diff --git a/CHANGELOG.md b/CHANGELOG.md index d128694..56b6e71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.0.2-rc.3 +- 把废弃的@ohos/fileio变更为@ohos.file.fs + ## 2.0.2-rc.2 - 捕获判断文件夹接口异常导致应用闪退问题 diff --git a/README-en.md b/README-en.md index aac87e8..aa7ac51 100644 --- a/README-en.md +++ b/README-en.md @@ -72,13 +72,13 @@ console.log(String.fromCharCode.aplly(null, new Uint8Array(data))); Cache a file synchronously. ```typescript -import fileio from '@ohos/fileio'; +import fs from '@ohos.file.fs'; let path = '/data/storage/el2/base/com.example.disklrucache/entry/files/testFile.txt'; -let fd = fileio.openSync(path, 0o2); -let length = fileio.statSync(path).size; +let fd = fs.openSync(path, 0o2); +let length = fs.statSync(path).size; let data = new ArrayBuffer(length); -fileio.readSync(fd, data); +fs.readSync(fd, data); this.testDiskLruCache.set('testFile', data); ``` @@ -104,19 +104,19 @@ this.testDiskLruCache.setAsync('test', value).then(() => { Cache a file asynchronously, and obtain a file from the cache asynchronously. ```typescript -import fileio from '@ohos/fileio'; +import fs from '@ohos.file.fs'; let path = '/data/storage/el2/base/com.example.disklrucache/entry/files/testFile.txt'; -let fd = fileio.openSync(path, 0o2); -let length = fileio.statSync(path).size; +let file = fs.openSync(path, 0o2); +let length = fs.statSync(path).size; let value = new ArrayBuffer(length); -fileio.readSync(fd, data); +fs.readSync(file.fd, data); this.testDiskLruCache.setAsync('test', value).then(() => { - this.testDiskLruCache.getAsync('test').then((data) => { - console.log(String.fromCharCode.aplly(null, new Uint8Array(data))); - }) + this.testDiskLruCache.getAsync('test').then((data) => { + console.log(String.fromCharCode.aplly(null, new Uint8Array(data))); + }) }).catch((err) => { - console.log('err =' + err); + console.log('err =' + err); }) ``` diff --git a/README.md b/README.md index ef14750..9c3abef 100644 --- a/README.md +++ b/README.md @@ -72,13 +72,13 @@ console.log(String.fromCharCode.aplly(null, new Uint8Array(data))); 同步设置文件磁盘缓存数据。 ```typescript -import fileio from '@ohos/fileio'; +import fs from '@ohos.file.fs'; let path = '/data/storage/el2/base/com.example.disklrucache/entry/files/testFile.txt'; -let fd = fileio.openSync(path, 0o2); -let length = fileio.statSync(path).size; +let fd = fs.openSync(path, 0o2); +let length = fs.statSync(path).size; let data = new ArrayBuffer(length); -fileio.readSync(fd, data); +fs.readSync(fd, data); this.testDiskLruCache.set('testFile', data); ``` @@ -104,13 +104,13 @@ this.testDiskLruCache.setAsync('test', value).then(() => { 异步设置文件磁盘缓存数据和异步获取文件磁盘缓存数据。 ```typescript -import fileio from '@ohos/fileio'; +import fs from '@ohos.file.fs'; let path = '/data/storage/el2/base/com.example.disklrucache/entry/files/testFile.txt'; -let fd = fileio.openSync(path, 0o2); -let length = fileio.statSync(path).size; +let file = fs.openSync(path, 0o2); +let length = fs.statSync(path).size; let value = new ArrayBuffer(length); -fileio.readSync(fd, data); +fs.readSync(file.fd, data); this.testDiskLruCache.setAsync('test', value).then(() => { this.testDiskLruCache.getAsync('test').then((data) => { console.log(String.fromCharCode.aplly(null, new Uint8Array(data))); diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index bdaf5b9..232b130 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -4,7 +4,7 @@ "name": "entry", "description": "example description", "repository": {}, - "version": "2.0.2-rc.2", + "version": "2.0.2-rc.3", "dependencies": { "@ohos/disklrucache": "file:../library" } diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 4edf057..6d4c265 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ import { DiskLruCache } from '@ohos/disklrucache' -import fileio from '@ohos.fileio'; +import fs from '@ohos.file.fs'; import { GlobalContext } from "../entryability/GlobalContext" @@ -157,7 +157,7 @@ struct Index { this.testDiskLruCache.getFileToPathAsync(key).then((data) => { let index: number = data.lastIndexOf('/') let newPath: string = data.substring(0, index) + '/' + name + '.' + key - fileio.copyFileSync(data, newPath) + fs.copyFileSync(data, newPath) this.imageSrc = 'file://' + newPath }).catch((err: Error) => { this.imageSrc = undefined diff --git a/entry/src/ohosTest/ets/test/DiskLruCacheTest.test.ets b/entry/src/ohosTest/ets/test/DiskLruCacheTest.test.ets index 8c8da49..47eb9a9 100644 --- a/entry/src/ohosTest/ets/test/DiskLruCacheTest.test.ets +++ b/entry/src/ohosTest/ets/test/DiskLruCacheTest.test.ets @@ -15,7 +15,7 @@ import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { DiskLruCache, DiskCacheEntry } from '@ohos/disklrucache'; -import fileio from '@ohos.fileio'; +import fs from '@ohos.file.fs'; import { GlobalContext } from "../testability/GlobalContext" @@ -42,12 +42,12 @@ export default function DiskLruCacheTest() { let data = GlobalContext.getContext().getObject("filesDir") as string let cache: DiskLruCache = DiskLruCache.create(context); let path = data + '/testFile.txt'; - let fd = fileio.openSync(path, 0o102, 0o666); - fileio.writeSync(fd, "hello, world!"); - let length = fileio.statSync(path).size; - let dataarr = new ArrayBuffer(length); - fileio.readSync(fd, dataarr); - cache.set('testFile', dataarr); + let file = fs.openSync(path, 0o102); + fs.writeSync(file.fd, "hello, world!"); + let length = fs.statSync(path).size; + let dataArr = new ArrayBuffer(length); + fs.readSync(file.fd, dataArr); + cache.set('testFile', dataArr); expect(cache.get('testFile').byteLength == 13).assertTrue() cache.cleanCacheData(); }) diff --git a/entry/src/ohosTest/ets/test/TestInterfaceResponseTime.test.ets b/entry/src/ohosTest/ets/test/TestInterfaceResponseTime.test.ets index bd4a045..6602471 100644 --- a/entry/src/ohosTest/ets/test/TestInterfaceResponseTime.test.ets +++ b/entry/src/ohosTest/ets/test/TestInterfaceResponseTime.test.ets @@ -21,7 +21,7 @@ export default function telephonyPerfJsunit(){ const BASE_COUNT=2000 const HTTP_COUNT=2 const BASELINE_HASSIMECASR=500 - const BASELINE_CREATEHTTP=500 + const BASELINE_CREATEHTTP=800 const BASELINE_REQUEST=2500 const BASELINE_DESTROY=30 diff --git a/library/oh-package.json5 b/library/oh-package.json5 index c9b8881..a28307e 100644 --- a/library/oh-package.json5 +++ b/library/oh-package.json5 @@ -13,7 +13,7 @@ "main": "index.ets", "repository": "https://gitee.com/openharmony-sig/ohos_disklrucache", "type": "module", - "version": "2.0.2-rc.2", + "version": "2.0.2-rc.3", "dependencies": {}, "tags": [ "Tool" diff --git a/library/src/main/ets/components/cache/DiskLruCache.ts b/library/src/main/ets/components/cache/DiskLruCache.ts index 71df48c..6ff2f05 100644 --- a/library/src/main/ets/components/cache/DiskLruCache.ts +++ b/library/src/main/ets/components/cache/DiskLruCache.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import fileio from '@ohos.fileio' +import fs from '@ohos.file.fs'; import { CustomMap } from './CustomMap' import { FileUtils } from './FileUtils' import { FileReader } from './FileReader' @@ -97,7 +97,7 @@ export class DiskLruCache { // 判断日志文件是否存在,如果没有初始化创建 if (FileUtils.getInstance().exist(journalPath)) { - let stat = fileio.statSync(journalPath) + let stat = fs.statSync(journalPath) if (stat.size > 0) { FileUtils.getInstance().createFile(journalPathTemp) FileUtils.getInstance().copyFile(journalPath, journalPathTemp) @@ -349,7 +349,7 @@ export class DiskLruCache { if (lineData.length > 1) { if (lineData[0] != DiskLruCache.REMOVE) { filePath = this.path + lineData[1] - let fileStat = fileio.statSync(filePath) + let fileStat = fs.statSync(filePath) if (fileStat.isFile() && fileStat.size > 0) { this.size = this.size + fileStat.size FileUtils.getInstance().writeData(this.journalPath, line + FileReader.LF) diff --git a/oh-package.json5 b/oh-package.json5 index 1c96bf0..fa9448b 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -6,6 +6,6 @@ "name": "disklrucache", "description": "example description", "repository": {}, - "version": "2.0.2-rc.2", + "version": "2.0.2-rc.3", "dependencies": {} } -- Gitee