1.delete disklrucache native library

2.add @ohos/disklrucache dependence

Signed-off-by: dodozhou5 <abczp555555@163.com>
This commit is contained in:
dodozhou5 2022-08-23 01:50:06 -07:00
parent 744e896409
commit 36bffd3be2
13 changed files with 18 additions and 1078 deletions

View File

@ -1,3 +0,0 @@
/node_modules
/.preview
/build

View File

@ -1,5 +0,0 @@
{
"apiType": "stageMode",
"buildOption": {
}
}

View File

@ -1,3 +0,0 @@
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
module.exports = require('@ohos/hvigor-ohos-plugin').harTasks

View File

@ -1,20 +0,0 @@
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:// www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* disklrucache
*/
export * from './src/main/ets/components/disklrucache/DiskLruCache'
export * from './src/main/ets/components/disklrucache/DiskCacheEntry'

View File

@ -1,18 +0,0 @@
{
"license":"ISC",
"types":"",
"devDependencies":{
"@types/spark-md5":"^3.0.2"
},
"name":"@ohos/disklrucache",
"description":"a npm package which contains arkUI2.0 page",
"ohos":{
"org":""
},
"main":"index.ets",
"repository":{},
"version":"1.0.0",
"dependencies":{
"spark-md5":"^3.0.2"
}
}

View File

@ -1,115 +0,0 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export class CustomMap<K, V> {
map: Map<K, V> = new Map<K, V>()
/**
*
*
* @param key
*/
get(key: K): V | undefined {
if (key == null) {
throw new Error('key is null,checking the parameter');
}
return this.map.get(key)
}
/**
* key的缓存
*
* @param key
*/
hasKey(key: K) {
if (key == null) {
throw new Error('key is null,checking the parameter');
}
return this.map.has(key)
}
/**
*
*
* @param key
* @param value
*/
put(key: K, value: V): V | undefined {
if (key == null || value == null) {
throw new Error('key or value is invalid,checking the parameter');
}
let pre = this.map.get(key)
if (this.hasKey(key)) {
this.map.delete(key)
}
this.map.set(key, value);
return pre
}
/**
* ()
*
* @param key
*/
remove(key: K): boolean {
if (key == null) {
throw new Error('key is null,checking the parameter');
}
return this.map.delete(key)
}
/**
* key
*/
getFirstKey(): K { // keys()可以遍历后需要优化put()方法暂时仅获取index=0的key
return this.map.keys().next().value
}
/**
*
*/
isEmpty(): boolean {
return this.map.size == 0;
}
/**
*
*/
size(): number {
return this.map.size;
}
/**
* Map,. function(key,value,index){..}
*
* @param fn
*/
each(fn) {
this.map.forEach(fn)
}
/**
*
*/
clear() {
this.map.clear()
}
/**
* key
*/
keys(): IterableIterator<K> {
return this.map.keys()
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export class DiskCacheEntry {
// 缓存的key
key: string = ''
// 缓存文件大小
length: number = 0
constructor(key: string, length?: number) {
this.key = key
this.length = length
}
setKey(key: string) {
this.key = key
}
getKey(): string {
return this.key
}
setLength(length: number) {
this.length = length
}
getLength(): number {
return this.length
}
toString(): string {
return this.key + ' - ' + this.length
}
}

View File

@ -1,492 +0,0 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@ohos.fileio'
import { CustomMap } from './CustomMap'
import { FileUtils } from './FileUtils'
import { FileReader } from './FileReader'
import { DiskCacheEntry } from './DiskCacheEntry'
import SparkMD5 from "spark-md5"
export class DiskLruCache {
// 默认缓存数据最大值
private static readonly DEFAULT_MAX_SIZE: number = 300 * 1024 * 1024
// 默认缓存文件名
private static readonly DEFAULT_NAME: string = 'diskLruCache'
// 缓存journal文件名称
private static readonly journal: string = 'journal'
// 缓存journal备份文件名称
private static readonly journalTemp: string = 'journal_temp'
// 备份文件save标识符
private static readonly SAVE: string = 'save'
// 备份文件read标识符
private static readonly READ: string = 'read'
// 备份文件remove标识符
private static readonly REMOVE: string = 'remove'
// 缓存文件路径地址
private path: string = ''
// 缓存journal文件路径
private journalPath: string = ''
// 缓存journal备份文件路径
private journalPathTemp: string = ''
// 缓存数据最大值
private maxSize: number = DiskLruCache.DEFAULT_MAX_SIZE
// 当前缓存数据值
private size: number = 0
// 缓存数据集合
private cacheMap: CustomMap<string, DiskCacheEntry> = new CustomMap<string, DiskCacheEntry>()
private constructor(path: string, maxSize: number) {
this.path = path
this.maxSize = maxSize
this.journalPath = path + DiskLruCache.journal
this.journalPathTemp = path + DiskLruCache.journalTemp
}
/**
* path中的缓存
*
* @param path
* @param maxSize 3M
*/
public static create(context, maxSize?: number): DiskLruCache {
if (!!!context) {
throw new Error('DiskLruCache create context is empty, checking the parameter');
}
if (!!!maxSize) {
maxSize = DiskLruCache.DEFAULT_MAX_SIZE
}
if (maxSize <= 0) {
throw new Error("DiskLruCache create maxSize <= 0, checking the parameter");
}
// 使用默认应用在内部存储上的缓存路径,作为存储地址
let path = context.cacheDir + FileUtils.SEPARATOR + DiskLruCache.DEFAULT_NAME
if (!FileUtils.getInstance().existFolder(path)) {
FileUtils.getInstance().createFolder(path, true)
}
if (path.endsWith(FileUtils.SEPARATOR)) {
path = path
} else {
path = path + FileUtils.SEPARATOR
}
let journalPath = path + DiskLruCache.journal
let journalPathTemp = path + DiskLruCache.journalTemp
// 判断日志文件是否存在,如果没有初始化创建
if (FileUtils.getInstance().exist(journalPath)) {
let stat = fileio.statSync(journalPath)
if (stat.size > 0) {
FileUtils.getInstance().createFile(journalPathTemp)
FileUtils.getInstance().copyFile(journalPath, journalPathTemp)
let diskLruCache: DiskLruCache = new DiskLruCache(path, maxSize)
diskLruCache.readJournal(journalPathTemp)
diskLruCache.resetJournalFile()
return diskLruCache
} else {
return new DiskLruCache(path, maxSize)
}
} else {
FileUtils.getInstance().createFile(journalPath)
return new DiskLruCache(path, maxSize)
}
}
/**
* disk缓存最大数据值
*
* @param max
*/
setMaxSize(max: number) {
if (max <= 0 || max > DiskLruCache.DEFAULT_MAX_SIZE) {
throw new Error('setMaxSize error, checking the parameter');
}
this.maxSize = max
this.trimToSize()
}
/**
* disk缓存数据
*
* @param key
* @param content
*/
set(key: string, content: ArrayBuffer | string) {
if (!!!key) {
throw new Error('key is null, checking the parameter')
}
let fileSize
if (content instanceof ArrayBuffer) {
if (content == null || content.byteLength == 0) {
throw new Error('content is null. checking the parameter')
}
fileSize = content.byteLength
} else {
if (!!!content) {
throw new Error('content is null, checking the parameter')
}
fileSize = content.length;
}
if (this.fileSizeMoreThenMaxSize(fileSize)) {
throw new Error('content must be less then DiskLruCache Size, checking the parameter')
return
}
key = SparkMD5.hash(key)
this.size = this.size + fileSize
this.putCacheMap(key, fileSize)
FileUtils.getInstance().writeData(this.journalPath, DiskLruCache.SAVE + ' ' + key + FileReader.LF)
this.trimToSize()
let tempPath = this.path + key
FileUtils.getInstance().writeNewFile(tempPath, content)
}
/**
* disk缓存数据
*
* @param key
* @param content
*/
async setAsync(key: string, content: ArrayBuffer | string): Promise<void> {
if (!!!key) {
throw new Error('key is null, checking the parameter')
}
let fileSize
if (content instanceof ArrayBuffer) {
if (content == null || content.byteLength == 0) {
throw new Error('content is null. checking the parameter')
}
fileSize = content.byteLength
} else {
if (!!!content) {
throw new Error('content is null, checking the parameter')
}
fileSize = content.length;
}
if (this.fileSizeMoreThenMaxSize(fileSize)) {
throw new Error('content must be less then DiskLruCache Size, checking the parameter')
return
}
key = SparkMD5.hash(key)
this.size = this.size + fileSize
this.putCacheMap(key, fileSize)
await FileUtils.getInstance().writeDataAsync(this.journalPath, DiskLruCache.SAVE + ' ' + key + FileReader.LF)
this.trimToSize()
let tempPath = this.path + key
await FileUtils.getInstance().writeNewFileAsync(tempPath, content)
}
/**
* key缓存数据
*
* @param key key
*/
get(key: string): ArrayBuffer {
if (!!!key) {
throw new Error('key is null,checking the parameter');
}
key = SparkMD5.hash(key)
let path = this.path + key;
if (FileUtils.getInstance().exist(path)) {
let ab: ArrayBuffer = FileUtils.getInstance().readFile(path)
this.putCacheMap(key, ab.byteLength)
FileUtils.getInstance().writeData(this.journalPath, DiskLruCache.READ + ' ' + key + FileReader.LF)
return ab
} else {
return null;
}
}
/**
* key缓存数据
*
* @param key
*/
async getAsync(key: string): Promise<ArrayBuffer> {
if (!!!key) {
throw new Error('key is null,checking the parameter');
}
key = SparkMD5.hash(key)
let path = this.path + key;
if (FileUtils.getInstance().exist(path)) {
let ab: ArrayBuffer = await FileUtils.getInstance().readFileAsync(path)
this.putCacheMap(key, ab.byteLength)
await FileUtils.getInstance().writeDataAsync(this.journalPath, DiskLruCache.READ + ' ' + key + FileReader.LF)
return ab
} else {
return null;
}
}
/**
* key缓存数据绝对路径
*
* @param key
*/
getFileToPath(key: string): string {
if (!!!key) {
throw new Error('key is null,checking the parameter');
}
key = SparkMD5.hash(key);
let path = this.path + key;
if (FileUtils.getInstance().exist(path)) {
FileUtils.getInstance().writeData(this.journalPath, DiskLruCache.READ + ' ' + key + FileReader.LF);
return path
} else {
return null
}
}
/**
* key缓存数据绝对路径
*
* @param key
*/
async getFileToPathAsync(key: string): Promise<string> {
if (!!!key) {
throw new Error('key is null,checking the parameter');
}
key = SparkMD5.hash(key);
let path = this.path + key;
if (FileUtils.getInstance().exist(path)) {
await FileUtils.getInstance().writeDataAsync(this.journalPath, DiskLruCache.READ + ' ' + key + FileReader.LF);
return path
} else {
return null
}
}
/**
*
*/
getPath(): string{
return this.path;
}
/**
* key缓存数据
*
* @param key
*/
deleteCacheDataByKey(key: string): DiskCacheEntry {
if (!!!key) {
throw new Error('key is null,checking the parameter');
}
key = SparkMD5.hash(key)
let path = this.path + key;
if (FileUtils.getInstance().exist(path)) {
let ab = FileUtils.getInstance().readFile(path)
this.size = this.size - ab.byteLength
this.cacheMap.remove(key)
FileUtils.getInstance().writeData(this.journalPath, DiskLruCache.REMOVE + ' ' + key + FileReader.LF)
FileUtils.getInstance().deleteFile(path)
}
return this.cacheMap.get(key)
}
/**
*
*
* @param fn
*/
foreachDiskLruCache(fn) {
this.cacheMap.each(fn)
}
/**
* disk缓存数据
*/
cleanCacheData() {
this.cacheMap.each((value, key) => {
FileUtils.getInstance().deleteFile(this.path + key)
})
FileUtils.getInstance().deleteFile(this.journalPath)
this.cacheMap.clear()
this.size = 0
}
getCacheMap() {
return this.cacheMap;
}
/**
* DiskLruCache的size大小
*/
getSize() {
return this.size;
}
/**
* journal文件数据
*
* @param line
*/
private dealWithJournal(line: string) {
let filePath = ''
try {
let lineData = line.split(' ')
if (lineData.length > 1) {
if (lineData[0] != DiskLruCache.REMOVE) {
filePath = this.path + lineData[1]
let fileStat = fileio.statSync(filePath)
if (fileStat.isFile() && fileStat.size > 0) {
this.size = this.size + fileStat.size
FileUtils.getInstance().writeData(this.journalPath, line + FileReader.LF)
this.putCacheMap(lineData[1], fileStat.size)
}
} else {
if (this.cacheMap.hasKey(lineData[1])) {
let cacheEntry: DiskCacheEntry = this.cacheMap.get(lineData[1])
this.size = this.size - cacheEntry.getLength()
this.cacheMap.remove(lineData[1])
}
}
}
} catch (e) {
console.error('DiskLruCache - dealWithJournal e ' + e)
}
}
/**
* disk缓存数据
*
* @param key key
* @param path
*/
private setFileByPath(key: string, path: string) {
if (!!!key) {
throw new Error('key is null, checking the parameter')
}
if (!!!path || !FileUtils.getInstance().exist(path)) {
throw new Error('path is null or no exist file, checking the parameter')
}
let fileSize = FileUtils.getInstance().getFileSize(path)
if (fileSize == -1) {
throw new Error('path getFileSize error ')
}
key = SparkMD5.hash(key)
this.size = this.size + fileSize
this.putCacheMap(key, fileSize)
FileUtils.getInstance().writeData(this.journalPath, DiskLruCache.SAVE + ' ' + key + FileReader.LF)
this.trimToSize()
fileSize = FileUtils.getInstance().getFileSize(path)
FileUtils.getInstance().copyFile(path, this.path + key)
}
/**
* disk缓存数据
*
* @param key key
* @param path
*/
private async setFileByPathAsync(key: string, path: string): Promise<void> {
if (!!!key) {
throw new Error('key is null, checking the parameter')
}
if (!!!path || !FileUtils.getInstance().exist(path)) {
throw new Error('path is null or no exist file, checking the parameter')
}
let fileSize = FileUtils.getInstance().getFileSize(path)
if (fileSize == -1) {
throw new Error('path getFileSize error ')
}
key = SparkMD5.hash(key)
this.size = this.size + fileSize
this.putCacheMap(key, fileSize)
await FileUtils.getInstance().writeDataAsync(this.journalPath, DiskLruCache.SAVE + ' ' + key + FileReader.LF)
this.trimToSize()
fileSize = FileUtils.getInstance().getFileSize(path)
await FileUtils.getInstance().copyFileAsync(path, this.path + key)
}
/**
* journal文件数据
*/
private resetJournalFile() {
FileUtils.getInstance().clearFile(this.journalPath)
for (let key of this.cacheMap.keys()) {
FileUtils.getInstance().writeData(this.journalPath, DiskLruCache.SAVE + ' ' + key + FileReader.LF)
}
}
/**
* journal文件的缓存数据
*
* @param path
*/
private readJournal(path: string) {
let fileReader = new FileReader(path)
let line: string = ''
while (!fileReader.isEnd()) {
line = fileReader.readLine()
line = line.replace(FileReader.LF, '').replace(FileReader.CR, '')
this.dealWithJournal(line)
}
fileReader.close()
FileUtils.getInstance().deleteFile(this.journalPathTemp)
this.trimToSize()
}
/**
* map集合
*
* @param key
* @param length
*/
private putCacheMap(key: string, length?: number) {
if (length > 0) {
this.cacheMap.put(key, new DiskCacheEntry(key, length))
} else {
this.cacheMap.put(key, new DiskCacheEntry(key))
}
}
/**
* LRU算法删除多余缓存数据
*/
private trimToSize() {
while (this.size > this.maxSize) {
let tempKey: string = this.cacheMap.getFirstKey()
let fileSize = FileUtils.getInstance().getFileSize(this.path + tempKey)
if (fileSize > 0) {
this.size = this.size - fileSize
}
FileUtils.getInstance().deleteFile(this.path + tempKey)
this.cacheMap.remove(tempKey)
FileUtils.getInstance().writeData(this.journalPath, DiskLruCache.REMOVE + ' ' + tempKey + FileReader.LF)
}
}
/**
* DiskLruCache上限
*/
private fileSizeMoreThenMaxSize(fileSize: number): boolean{
if (fileSize > this.maxSize) {
return true;
}
return false;
}
}

View File

@ -1,99 +0,0 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@ohos.fileio'
export class FileReader {
// 换行符
static readonly LF: string = '\n'
// CR符
static readonly CR: string = '\r'
// 文件大小
fileLength: number = 0
// 读取的长度
length: number = 0
// 读写stream
stream: any = null
// 缓存buf
buf: ArrayBuffer = new ArrayBuffer(1)
/**
*
*
* @param path
*/
constructor(path: string) {
if (!!!path) {
throw new Error('FileReader constructor path is null, checking the parameter')
return;
}
this.stream = fileio.createStreamSync(path, 'r+');
let stat = fileio.statSync(path)
this.fileLength = stat.size
}
/**
*
*/
readLine(): string {
let line = ''
while (this.length < this.fileLength) {
this.stream.readSync(this.buf, { position: this.length })
this.length++
let temp = String.fromCharCode.apply(null, new Uint8Array(this.buf));
line = line + temp
// check CRLF
if (temp == FileReader.CR) {
// 边界判断 首先拿到下一个字符判断是否是LF 如果是CRLF需要再向后挪一位
if(this.length < this.fileLength) {
let nextBuf = new ArrayBuffer(1)
this.stream.readSync(nextBuf, { position: this.length })
let nextTemp = String.fromCharCode.apply(null, new Uint8Array(nextBuf))
// 如果是CRLF 需要给当前length+1 向后挪一位
if (nextTemp == FileReader.LF) {
this.length++
}
}
// 如果不是CRLF 只有一个CR结尾length不用变
return line;
} else {
// 判断LF情况
if (temp == FileReader.LF) {
return line
}
}
}
return line
}
/**
*
*/
isEnd() {
return this.fileLength <= 0 || this.length == this.fileLength
}
/**
* stream
*/
close() {
this.stream.closeSync()
}
}

View File

@ -1,240 +0,0 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fileio from '@ohos.fileio'
export class FileUtils {
static readonly SEPARATOR: string = '/'
private static sInstance: FileUtils
base64Str: string = ''
private constructor() {
}
/**
* FileUtils类
*/
public static getInstance(): FileUtils {
if (!this.sInstance) {
this.sInstance = new FileUtils();
}
return this.sInstance;
}
/**
*
*
* @param path
* @return number id
*/
createFile(path: string): number {
return fileio.openSync(path, 0o100, 0o664)
}
/**
*
*
* @param path
*/
deleteFile(path: string): void {
fileio.unlinkSync(path);
}
/**
*
*
* @param src
* @param dest
*/
copyFile(src: string, dest: string) {
fileio.copyFileSync(src, dest);
}
/**
*
*
* @param src
* @param dest
*/
async copyFileAsync(src: string, dest: string): Promise<void> {
await fileio.copyFile(src, dest);
}
/**
*
*
* @param path
*/
clearFile(path: string): number {
return fileio.openSync(path, 0o1000)
}
/**
* path写入数据
*
* @param path
* @param content
*/
writeData(path: string, content: ArrayBuffer | string) {
let fd = fileio.openSync(path, 0o102, 0o664)
let stat = fileio.statSync(path)
fileio.writeSync(fd, content, { position: stat.size })
fileio.closeSync(fd)
}
/**
* path写入数据
*
* @param path
* @param content
*/
async writeDataAsync(path: string, content: ArrayBuffer | string): Promise<void> {
let fd = await fileio.open(path, 0o102, 0o664)
let stat = await fileio.stat(path)
await fileio.write(fd, content, { position: stat.size })
await fileio.close(fd)
}
/**
* path文件是否存在
*
* @param path
*/
exist(path: string): boolean {
try {
let stat = fileio.statSync(path)
return stat.isFile()
} catch (e) {
console.error("FileUtils exist e " + e)
return false
}
}
/**
* path写入数据
*
* @param path
* @param data
*/
writeNewFile(path: string, data: ArrayBuffer | string) {
this.createFile(path)
this.writeFile(path, data)
}
/**
* path写入数据
*
* @param path
* @param data
*/
async writeNewFileAsync(path: string, data: ArrayBuffer | string): Promise<void> {
await fileio.open(path, 0o100, 0o664)
let fd = await fileio.open(path, 0o102, 0o664)
await fileio.ftruncate(fd)
await fileio.write(fd, data)
await fileio.fsync(fd)
await fileio.close(fd)
}
/**
* path的文件大小
*
* @param path
*/
getFileSize(path: string): number {
try {
let stat = fileio.statSync(path)
return stat.size
} catch (e) {
console.error("FileUtils getFileSize e " + e)
return -1
}
}
/**
* path的文件
*
* @param path
*/
readFile(path: string): ArrayBuffer {
let fd = fileio.openSync(path, 0o2);
let length = fileio.statSync(path).size
let buf = new ArrayBuffer(length);
fileio.readSync(fd, buf)
return buf
}
/**
* path的文件
*
* @param path
*/
async readFileAsync(path: string): Promise<ArrayBuffer> {
let stat = await fileio.stat(path);
let fd = await fileio.open(path, 0o2);
let length = stat.size;
let buf = new ArrayBuffer(length);
await fileio.read(fd, buf);
return buf
}
/**
*
*
* @param path
* @param recursive
*/
createFolder(path: string, recursive?: boolean) {
if (recursive) {
if (!this.existFolder(path)) {
let lastInterval = path.lastIndexOf(FileUtils.SEPARATOR)
if (lastInterval == 0) {
return
}
let newPath = path.substring(0, lastInterval)
this.createFolder(newPath, true)
if (!this.existFolder(path)) {
fileio.mkdirSync(path)
}
}
} else {
if (!this.existFolder(path)) {
fileio.mkdirSync(path)
}
}
}
/**
*
*
* @param path
*/
existFolder(path: string): boolean {
try {
let stat = fileio.statSync(path)
return stat.isDirectory()
} catch (e) {
console.error("FileUtils folder exist e " + e)
return false
}
}
private writeFile(path: string, content: ArrayBuffer | string) {
let fd = fileio.openSync(path, 0o102, 0o664)
fileio.ftruncateSync(fd)
fileio.writeSync(fd, content)
fileio.fsyncSync(fd)
fileio.closeSync(fd)
}
}

View File

@ -1,11 +0,0 @@
{
"module": {
"name": "disklrucache",
"type": "har",
"deviceTypes": [
"default",
"tablet"
],
"uiSyntax": "ets"
}
}

View File

@ -1,8 +0,0 @@
{
"string": [
{
"name": "page_show",
"value": "page from npm package"
}
]
}

View File

@ -15,7 +15,7 @@
"version": "1.0.2",
"dependencies": {
"pako": "^1.0.5",
"@ohos/disklrucache":"file:../disklrucache",
"@ohos/disklrucache": "^1.0.0",
"crc-32": "^1.2.0"
},
"tags": [