From cbbfb66616bc2659ed494851a5d26cde3c0f79f8 Mon Sep 17 00:00:00 2001 From: xinking129 Date: Fri, 12 Jul 2024 15:35:51 +0800 Subject: [PATCH] fix Flashback Signed-off-by: xinking129 --- .../src/main/ets/zlib/CompressFilesPage.ets | 5 +-- .../main/ets/zlib/ZLibInterfaceListPage.ets | 39 ++++++++++++------- .../ZipLib/entry/src/main/module.json5 | 3 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/CompressFilesPage.ets b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/CompressFilesPage.ets index b210555c9..0d138405d 100644 --- a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/CompressFilesPage.ets +++ b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/CompressFilesPage.ets @@ -145,7 +145,6 @@ struct CompressFilesPage { bottom: '11%' }); } - await fileList.put('fileNames', JSON.stringify(this.files.fileData)); await fileList.flush(); } @@ -222,9 +221,9 @@ struct CompressFilesPage { this.slectFileName.push(item); } else { this.isSelect = false; - let index = this.slectFileName.indexOf(item) + let index = this.slectFileName.indexOf(item); if (index !== -1) { - this.slectFileName.splice(index, 1) + this.slectFileName.splice(index, 1); } } }) diff --git a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/ZLibInterfaceListPage.ets b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/ZLibInterfaceListPage.ets index 3fadf0b54..fc7a9ff24 100644 --- a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/ZLibInterfaceListPage.ets +++ b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/ets/zlib/ZLibInterfaceListPage.ets @@ -53,10 +53,15 @@ struct ZLibInterfaceListPage { checksum.crc32(0, arrayBufferIn); try { // 压缩数据 - await zip.deflate({ nextIn: arrayBufferIn, availableIn: BUFFER_SIZE, nextOut: arrayBufferOut, - availableOut: BUFFER_SIZE }, zlib.CompressFlushMode.FINISH).then((data) => { + await zip.deflate({ + nextIn: arrayBufferIn, + availableIn: BUFFER_SIZE, + nextOut: arrayBufferOut, + availableOut: BUFFER_SIZE + }, zlib.CompressFlushMode.FINISH).then((data) => { // 将压缩后的buffer写入zlibDeflateFile.txt文件中 - let zlibDeflateFile = fileIo.openSync(pathDir + '/zlibDeflateFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + let zlibDeflateFile = + fileIo.openSync(pathDir + '/zlibDeflateFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); fileIo.writeSync(zlibDeflateFile.fd, arrayBufferOut); fileIo.closeSync(zlibDeflateFile); promptAction.showToast({ @@ -80,15 +85,20 @@ struct ZLibInterfaceListPage { checksum.crc32(0, arrayBufferOut); try { // 解压数据 - await zip.inflate({ nextIn: arrayBufferOut, availableIn: BUFFER_SIZE, nextOut: inflateArrayBufferOut, - availableOut: BUFFER_SIZE }, zlib.CompressFlushMode.NO_FLUSH).then((data) => { + await zip.inflate({ + nextIn: arrayBufferOut, + availableIn: BUFFER_SIZE, + nextOut: inflateArrayBufferOut, + availableOut: BUFFER_SIZE + }, zlib.CompressFlushMode.NO_FLUSH).then((data) => { let array = new Uint8Array(inflateArrayBufferOut); let dataString = ''; for (let i = 0; i < array.length; i++) { dataString += String.fromCharCode(array[i]); } // 将解压后的数据写入zlibInflateFile.txt文件中 - let zlibInflateFile = fileIo.openSync(pathDir + '/zlibInflateFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + let zlibInflateFile = + fileIo.openSync(pathDir + '/zlibInflateFile.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); fileIo.writeSync(zlibInflateFile.fd, dataString); fileIo.closeSync(zlibInflateFile); // 验证压缩与解压的数据是否一致 @@ -121,7 +131,7 @@ struct ZLibInterfaceListPage { // 创建gzip对象 let gzip = zlib.createGZipSync(); // 打开.gz文件,对文件进行写操作 - gzip.gzopen(path, 'wb'); + await gzip.gzopen(path, 'wb'); let str = STRING_DATA; let arrayBufferIn = new ArrayBuffer(BUFFER_SIZE); let byteArray = new Uint8Array(arrayBufferIn); @@ -130,7 +140,7 @@ struct ZLibInterfaceListPage { } try { // 将bufferWithData压缩并写入文件 - gzip.gzfwrite(arrayBufferIn, 8, 2).then((data) => { + await gzip.gzfwrite(arrayBufferIn, 8, 2).then((data) => { promptAction.showToast({ message: $r('app.string.gzip_compress_success', str), bottom: '11%' @@ -142,16 +152,16 @@ struct ZLibInterfaceListPage { bottom: '11%' }); } - gzip.gzflush(0); - gzip.gzclose(); + await gzip.gzflush(0); + await gzip.gzclose(); await sleep(SLEEP_TIME); // 打开.gz文件,对文件进行读操作 - gzip.gzopen(path, 'rb'); + await gzip.gzopen(path, 'rb'); try { let bufferWithDataOut = new ArrayBuffer(BUFFER_SIZE); // 从.gz文件中读取和解压数据 - gzip.gzfread(bufferWithDataOut, 8, 2).then((data) => { + await gzip.gzfread(bufferWithDataOut, 8, 2).then((data) => { let array = new Uint8Array(bufferWithDataOut); let dataString = ''; for (let i = 0; i < array.length; i++) { @@ -162,7 +172,8 @@ struct ZLibInterfaceListPage { message: $r('app.string.gzip_uncompress_success', dataString), bottom: '11%' }); - let gzipFile = fileIo.openSync(pathDir + '/gzipTest.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + let gzipFile = + fileIo.openSync(pathDir + '/gzipTest.txt', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); fileIo.writeSync(gzipFile.fd, dataString); fileIo.closeSync(gzipFile); } @@ -173,7 +184,7 @@ struct ZLibInterfaceListPage { bottom: '11%' }); } - gzip.gzclose(); + await gzip.gzclose(); hilog.info(DOMAIN, TAG, BUNDLE + `gzipDecompression end`); } diff --git a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/module.json5 b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/module.json5 index 22298c9ff..af9cd6d99 100644 --- a/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/module.json5 +++ b/code/LaunguageBaseClassLibrary/ZipLib/entry/src/main/module.json5 @@ -21,8 +21,7 @@ "mainElement": "EntryAbility", "deviceTypes": [ "default", - "tablet", - "2in1" + "tablet" ], "deliveryWithInstall": true, "installationFree": false,