diff --git a/OhosVideoCache/CHANGELOG.md b/OhosVideoCache/CHANGELOG.md index d2670f1410ec24533063ebea007c78dbd9029a82..8df24108cad17a40f130ddd632bee2cd2458c139 100644 --- a/OhosVideoCache/CHANGELOG.md +++ b/OhosVideoCache/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.0.3-rc.2 +1. Optimize video caching and playback speed + ## 1.0.3-rc.1 1. Fix the issue of excessive data usage diff --git a/OhosVideoCache/entry/oh-package.json5 b/OhosVideoCache/entry/oh-package.json5 index 38249189d0e200f294e5e6966fa255719b7ca00d..61b25645136926036e66133b7f1330b8bbeea163 100644 --- a/OhosVideoCache/entry/oh-package.json5 +++ b/OhosVideoCache/entry/oh-package.json5 @@ -1,6 +1,6 @@ { "name": "entry", - "version": "1.0.3-rc.1", + "version": "1.0.3-rc.2", "description": "Please describe the basic information.", "main": "", "author": "", diff --git a/OhosVideoCache/library/Index.ts b/OhosVideoCache/library/Index.ets similarity index 100% rename from OhosVideoCache/library/Index.ts rename to OhosVideoCache/library/Index.ets diff --git a/OhosVideoCache/library/oh-package.json5 b/OhosVideoCache/library/oh-package.json5 index a1c134c577c17467842e52bb9967c551dcb9ac4c..009f121cfcc19d3275160753da7126695f0c01ef 100644 --- a/OhosVideoCache/library/oh-package.json5 +++ b/OhosVideoCache/library/oh-package.json5 @@ -1,10 +1,10 @@ { "name": "@ohos/video-cache", - "version": "1.0.3-rc.1", + "version": "1.0.3-rc.2", "type": "module", "types": "", "description": "OhosVideoCache allows to add caching support to your IjkPlayer/AvPlayer or any another player with help of single line!", - "main": "Index.ts", + "main": "Index.ets", "author": "ohos_tpc", "ohos": { "org": "opensource" diff --git a/OhosVideoCache/library/src/main/ets/ByteArrayCache.ts b/OhosVideoCache/library/src/main/ets/ByteArrayCache.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/ByteArrayCache.ts rename to OhosVideoCache/library/src/main/ets/ByteArrayCache.ets diff --git a/OhosVideoCache/library/src/main/ets/ByteArraySource.ts b/OhosVideoCache/library/src/main/ets/ByteArraySource.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/ByteArraySource.ts rename to OhosVideoCache/library/src/main/ets/ByteArraySource.ets diff --git a/OhosVideoCache/library/src/main/ets/Cache.ts b/OhosVideoCache/library/src/main/ets/Cache.ets similarity index 94% rename from OhosVideoCache/library/src/main/ets/Cache.ts rename to OhosVideoCache/library/src/main/ets/Cache.ets index 07c5b6e29c8dd8c353925faf3b44ec1bcc647c21..c2f2aebca86c85b42673f1770cab3b08218491a1 100644 --- a/OhosVideoCache/library/src/main/ets/Cache.ts +++ b/OhosVideoCache/library/src/main/ets/Cache.ets @@ -20,7 +20,7 @@ export interface Cache { read(buffer: ArrayBuffer, offset: number, length: number): number; - append(data: ArrayBuffer, length: number); + append(data: ArrayBuffer, length: number): void; close(): Promise; diff --git a/OhosVideoCache/library/src/main/ets/CacheListener.ts b/OhosVideoCache/library/src/main/ets/CacheListener.ets similarity index 96% rename from OhosVideoCache/library/src/main/ets/CacheListener.ts rename to OhosVideoCache/library/src/main/ets/CacheListener.ets index 4346fda13066ca277e6e93ed796fac14fdc6346e..dd133b9ca52e404e35bd5160e14c874ab1458184 100644 --- a/OhosVideoCache/library/src/main/ets/CacheListener.ts +++ b/OhosVideoCache/library/src/main/ets/CacheListener.ets @@ -14,5 +14,5 @@ */ export interface CacheListener { - onCacheAvailable(cacheFilePath: string, url: string, percentsAvailable: number); + onCacheAvailable(cacheFilePath: string, url: string, percentsAvailable: number): void; } \ No newline at end of file diff --git a/OhosVideoCache/library/src/main/ets/Config.ts b/OhosVideoCache/library/src/main/ets/Config.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/Config.ts rename to OhosVideoCache/library/src/main/ets/Config.ets diff --git a/OhosVideoCache/library/src/main/ets/GetRequest.ts b/OhosVideoCache/library/src/main/ets/GetRequest.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/GetRequest.ts rename to OhosVideoCache/library/src/main/ets/GetRequest.ets diff --git a/OhosVideoCache/library/src/main/ets/HttpProxyCache.ts b/OhosVideoCache/library/src/main/ets/HttpProxyCache.ets similarity index 97% rename from OhosVideoCache/library/src/main/ets/HttpProxyCache.ts rename to OhosVideoCache/library/src/main/ets/HttpProxyCache.ets index 4457f6723359c08293dd15afa76228a65cb320e6..7960c2b02f63f854695a62f95abd1c6509f337f6 100644 --- a/OhosVideoCache/library/src/main/ets/HttpProxyCache.ts +++ b/OhosVideoCache/library/src/main/ets/HttpProxyCache.ets @@ -121,7 +121,7 @@ export default class HttpProxyCache extends ProxyCache { } const ctx = this; await new Promise((resolve, reject) => { - let newSourceNoCache = new HttpUrlSource([this.source]); + let newSourceNoCache = new HttpUrlSource([this.source], true); try { class TempDataBackListener implements DataBackListener { onDataEnd() { @@ -135,6 +135,10 @@ export default class HttpProxyCache extends ProxyCache { onDataReceive(data: ArrayBuffer) { ctx.receiveSize += data.byteLength; + if (ctx.stopped) { + newSourceNoCache.close(); + return; + } let msg: socket.TCPSendOptions = { data: data } diff --git a/OhosVideoCache/library/src/main/ets/HttpProxyCacheServer.ts b/OhosVideoCache/library/src/main/ets/HttpProxyCacheServer.ets similarity index 97% rename from OhosVideoCache/library/src/main/ets/HttpProxyCacheServer.ts rename to OhosVideoCache/library/src/main/ets/HttpProxyCacheServer.ets index 14200123256b2358dd07e409d77491da986398f5..5ef121e5822f72aadb96a99f7c5d17f45199954a 100644 --- a/OhosVideoCache/library/src/main/ets/HttpProxyCacheServer.ts +++ b/OhosVideoCache/library/src/main/ets/HttpProxyCacheServer.ets @@ -94,8 +94,7 @@ export default class HttpProxyCacheServer { this.serverSocket?.on("connect", async (clientSocket: socket.TCPSocketConnection) => { clientSocket?.on("message", (data: MessageCallBackBean) => { if (data && data.message) { - let info = buffer.from(data.message).toString(); - self.processSocket(info, clientSocket) + self.processSocket(data.message, clientSocket) } }) clientSocket?.on("error", (err: Error) => { @@ -118,10 +117,10 @@ export default class HttpProxyCacheServer { } } - async processSocket(requestInfo: string, severConnect: socket.TCPSocketConnection) { + async processSocket(requestInfo: ArrayBuffer, severConnect: socket.TCPSocketConnection) { let self = this; try { - let request = GetRequest.read(buffer.from(requestInfo).buffer); + let request = GetRequest.read(requestInfo); let url = ProxyCacheUtils.decode(request.uri); if (self.pinger && self.pinger.isPingRequest(url)) { await self.pinger?.responseToPing(severConnect); @@ -336,7 +335,7 @@ export default class HttpProxyCacheServer { this.closeSocket(severConnect, isCloseByClient); } - private closeSocket(severConnect: socket.TCPSocketConnection, isCloseByClient: boolean): void { + private closeSocket(severConnect: socket.TCPSocketConnection | null, isCloseByClient: boolean): void { // 客户端主动断开连接的情况下 不做处理 否则可能将正在执行的其他连接断开 try { // 暂不处理 该方法关闭可能会关掉当前传输数据的severConnect而不是已经不再使用的severConnect 改为在HttpProxyCache里面关闭。 diff --git a/OhosVideoCache/library/src/main/ets/HttpProxyCacheServerBuilder.ts b/OhosVideoCache/library/src/main/ets/HttpProxyCacheServerBuilder.ets similarity index 92% rename from OhosVideoCache/library/src/main/ets/HttpProxyCacheServerBuilder.ts rename to OhosVideoCache/library/src/main/ets/HttpProxyCacheServerBuilder.ets index ba563037f3abd4619df0b8d7a79db72759d905c4..e0fe58881303eeb78dbe2b916ec1d7ad1e80f221 100644 --- a/OhosVideoCache/library/src/main/ets/HttpProxyCacheServerBuilder.ts +++ b/OhosVideoCache/library/src/main/ets/HttpProxyCacheServerBuilder.ets @@ -29,11 +29,11 @@ import SourceInfoStorageFactory from './sourcestorage/SourceInfoStorageFactory'; import StorageUtils from './StorageUtils'; export default class HttpProxyCacheServerBuilder { private DEFAULT_MAX_SIZE: number = 512 * 1024 * 1024; - private cacheRoot: string; - private fileNameGenerator: FileNameGenerator; - private diskUsage: DiskUsage; - private sourceInfoStorage: SourceInfoStorage; - private headerInjector: HeaderInjector; + private cacheRoot: string = ''; + private fileNameGenerator: FileNameGenerator | undefined = undefined; + private diskUsage: DiskUsage | undefined = undefined; + private sourceInfoStorage: SourceInfoStorage | undefined = undefined; + private headerInjector: HeaderInjector | undefined = undefined; private context: Context; public constructor(context: Context) { @@ -147,6 +147,6 @@ export default class HttpProxyCacheServerBuilder { } public buildConfig(): Config { - return new Config(this.cacheRoot, this.fileNameGenerator, this.diskUsage, this.sourceInfoStorage, this.headerInjector); + return new Config(this.cacheRoot, this.fileNameGenerator!, this.diskUsage!, this.sourceInfoStorage!, this.headerInjector!); } } \ No newline at end of file diff --git a/OhosVideoCache/library/src/main/ets/HttpProxyCacheServerClients.ts b/OhosVideoCache/library/src/main/ets/HttpProxyCacheServerClients.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/HttpProxyCacheServerClients.ts rename to OhosVideoCache/library/src/main/ets/HttpProxyCacheServerClients.ets diff --git a/OhosVideoCache/library/src/main/ets/HttpUrlSource.ts b/OhosVideoCache/library/src/main/ets/HttpUrlSource.ets similarity index 89% rename from OhosVideoCache/library/src/main/ets/HttpUrlSource.ts rename to OhosVideoCache/library/src/main/ets/HttpUrlSource.ets index 48a8e7c98f7f9cceb8eb17d75242294027823364..85c854f38793f8e3d0710ccddbdfcb16f8bfc53f 100644 --- a/OhosVideoCache/library/src/main/ets/HttpUrlSource.ts +++ b/OhosVideoCache/library/src/main/ets/HttpUrlSource.ets @@ -38,15 +38,15 @@ export default class HttpUrlSource implements Source { private connection: http.HttpRequest | null = null; private callBack: DataBackListener | null = null; private isInitFinish: boolean = false; + private interId: number = (0 - Number.MAX_VALUE); + private lastLocation: string = ''; private isHeaderDealFinish: boolean = false; private isDataFinish: boolean = false; private cacheData: Queue = new Queue(); - private interId: number = (0 - Number.MAX_VALUE); - private lastLocation: string = ''; - // private inputStream: InputStream; + private useInterVal: boolean = false; - constructor(args: string | Array) { + constructor(args: string | Array, useInterVal?: boolean) { if (!args || args.length < 1) { throw new Error('params can not be null') } @@ -120,25 +120,28 @@ export default class HttpUrlSource implements Source { self.notifyInitFinish() } - self.interId = setInterval(() => { - if (!self.callBack) { - return; - } - if (!self.isHeaderDealFinish) { - return - } - if (self?.sourceInfo?.url?.indexOf('ping') != -1) { - return; - } - if (self?.cacheData?.length > 0) { - self?.callBack?.onDataReceive(self?.cacheData?.pop()) - } else { - if (self.isDataFinish) { - self.isHeaderDealFinish = false; - self.callBack?.onDataEnd() + if (useInterVal) { + this.useInterVal = true; + self.interId = setInterval(() => { + if (!self.callBack) { + return; } - } - }, 20) + if (!self.isHeaderDealFinish) { + return + } + if (self?.sourceInfo?.url?.indexOf('ping') != -1) { + return; + } + if (self?.cacheData?.length > 0) { + self?.callBack?.onDataReceive(self?.cacheData?.pop()) + } else { + if (self.isDataFinish) { + self.isHeaderDealFinish = false; + self.callBack?.onDataEnd() + } + } + }, 20) + } } notifyInitFinish() { @@ -151,12 +154,16 @@ export default class HttpUrlSource implements Source { close(): void { try { - this.cacheData = new Queue(); + if(this.useInterVal){ + this.cacheData = new Queue(); + } if (this.interId != 0 - Number.MAX_VALUE) { clearInterval(this.interId) } emitter.off(VideoCacheConstant.HTTP_URL_SOURCE_READY_ID) - this.isHeaderDealFinish = false; + if(this.useInterVal){ + this.isHeaderDealFinish = false; + } this.connection?.off('headersReceive'); this.connection?.off('dataReceive'); this.connection?.off('dataReceiveProgress'); @@ -188,7 +195,7 @@ export default class HttpUrlSource implements Source { await this.fetchContentInfo(); } return new Promise((resolve, reject) => { - resolve(this.sourceInfo?.length) + resolve(this.sourceInfo?.length?? -1); }); } @@ -209,8 +216,10 @@ export default class HttpUrlSource implements Source { async open(offset: number): Promise { const self = this - self.isHeaderDealFinish = false; - self.isDataFinish = false; + if (this.useInterVal) { + self.isHeaderDealFinish = false; + self.isDataFinish = false; + } await self.checkInit() try { return new Promise(async (resolve, reject) => { @@ -237,14 +246,20 @@ export default class HttpUrlSource implements Source { await self.sourceInfoStorage?.put(self.sourceInfo!.url, self.sourceInfo); self?.callBack?.onDataStart(); } - self.isHeaderDealFinish = true; + if (this.useInterVal) { + self.isHeaderDealFinish = true; + } } }) self.connection?.on('dataReceive', (data: ArrayBuffer) => { if (self?.sourceInfo?.url?.indexOf('ping') != -1) { self?.callBack?.onDataReceive(data); } else { - self?.cacheData?.add(data); + if (this.useInterVal) { + self?.cacheData?.add(data); + } else { + self?.callBack?.onDataReceive(data); + } } }) self.connection?.on('dataReceiveProgress', (progress: ProgressValue) => { @@ -253,19 +268,27 @@ export default class HttpUrlSource implements Source { self.connection!!.on('dataEnd', () => { if (self?.sourceInfo?.url?.indexOf('ping') != -1) { self?.callBack?.onDataEnd(); - } else if (self?.cacheData?.length > 1) { - self.isDataFinish = true; + } else { + if (this.useInterVal && self?.cacheData?.length > 1) { + self.isDataFinish = true; + } else { + self.callBack?.onDataEnd(); + } } }) let option: http.HttpRequestOptions = self.initRequestParam(offset, -1) - self.cacheData = new Queue(); + if (this.useInterVal) { + self.cacheData = new Queue(); + } await self.connection?.requestInStream(self.sourceInfo!!.url, option) return resolve() }) } catch (err) { - self.isHeaderDealFinish = false; + if (this.useInterVal) { + self.isHeaderDealFinish = false; + } self.connection?.destroy() return new Promise((resolve, reject) => { return reject(new ProxyCacheException("Error opening connection for " + self.sourceInfo!!.url + " with offset " + offset + err.message)) @@ -309,7 +332,9 @@ export default class HttpUrlSource implements Source { let option = self.initRequestParam(0, 10000) urlConnection.requestInStream(self.sourceInfo!!.url, option) }) - urlConnection?.destroy(); + if(urlConnection !== null){ + (urlConnection as http.HttpRequest).destroy(); + } return Promise.resolve(); } catch (err) { console.error("Error fetching info from " + self.sourceInfo!!.url + err.message); @@ -419,6 +444,6 @@ export default class HttpUrlSource implements Source { } public toString(): string { - return "HttpUrlSource{sourceInfo='" + this.sourceInfo.toString() + "}"; + return "HttpUrlSource{sourceInfo='" + this.sourceInfo?.toString() + "}"; } } \ No newline at end of file diff --git a/OhosVideoCache/library/src/main/ets/IgnoreHostProxySelector.ts b/OhosVideoCache/library/src/main/ets/IgnoreHostProxySelector.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/IgnoreHostProxySelector.ts rename to OhosVideoCache/library/src/main/ets/IgnoreHostProxySelector.ets diff --git a/OhosVideoCache/library/src/main/ets/InterruptedProxyCacheException.ts b/OhosVideoCache/library/src/main/ets/InterruptedProxyCacheException.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/InterruptedProxyCacheException.ts rename to OhosVideoCache/library/src/main/ets/InterruptedProxyCacheException.ets diff --git a/OhosVideoCache/library/src/main/ets/MimeUtils.ts b/OhosVideoCache/library/src/main/ets/MimeUtils.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/MimeUtils.ts rename to OhosVideoCache/library/src/main/ets/MimeUtils.ets diff --git a/OhosVideoCache/library/src/main/ets/Pinger.ts b/OhosVideoCache/library/src/main/ets/Pinger.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/Pinger.ts rename to OhosVideoCache/library/src/main/ets/Pinger.ets diff --git a/OhosVideoCache/library/src/main/ets/Preconditions.ts b/OhosVideoCache/library/src/main/ets/Preconditions.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/Preconditions.ts rename to OhosVideoCache/library/src/main/ets/Preconditions.ets diff --git a/OhosVideoCache/library/src/main/ets/ProxyCache.ts b/OhosVideoCache/library/src/main/ets/ProxyCache.ets similarity index 95% rename from OhosVideoCache/library/src/main/ets/ProxyCache.ts rename to OhosVideoCache/library/src/main/ets/ProxyCache.ets index 60bbc99f41368ad81e2ad689256747946ecfcbd5..5c8030b0c35f2c878bb1031d79ab9b387599df40 100644 --- a/OhosVideoCache/library/src/main/ets/ProxyCache.ts +++ b/OhosVideoCache/library/src/main/ets/ProxyCache.ets @@ -46,17 +46,18 @@ export default class ProxyCache { } let self = this; let lastAvailable: number = - 1; - while (!self.cache.isCompleted() && self.cache.available() < (offset + length) && !self.stopped) { + + while (self.cache && !self.cache.isCompleted() && self.cache.available() < (offset + length) && !self.stopped) { this.readSourceAsync(); await self.waitForSourceData(); self.checkReadSourceErrorsCount(); if(self.cache?.available() == lastAvailable) { this.tryComplete(); } else { - lastAvailable = self.cache?.available(); + lastAvailable = self.cache?.available() ?? -1; } } - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { let read = self.cache?.read(buffer, offset, length); if (self.cache?.isCompleted() && self.percentsAvailable != 100) { self.percentsAvailable = 100; @@ -65,7 +66,7 @@ export default class ProxyCache { if (self.stopped) { return resolve(-1); } else { - return resolve(read); + return resolve(read?? -1); } }) } @@ -115,7 +116,7 @@ export default class ProxyCache { self.timeoutId = (0 - Number.MAX_VALUE) return resolve() } - }, 1000) + }, 200) }) } @@ -159,7 +160,7 @@ export default class ProxyCache { } async onDataStart() { - sourceAvailable = await self?.source?.length(); + sourceAvailable = await self?.source?.length()?? -1; self.setFileLength(sourceAvailable); } diff --git a/OhosVideoCache/library/src/main/ets/ProxyCacheException.ts b/OhosVideoCache/library/src/main/ets/ProxyCacheException.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/ProxyCacheException.ts rename to OhosVideoCache/library/src/main/ets/ProxyCacheException.ets diff --git a/OhosVideoCache/library/src/main/ets/ProxyCacheUtils.ts b/OhosVideoCache/library/src/main/ets/ProxyCacheUtils.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/ProxyCacheUtils.ts rename to OhosVideoCache/library/src/main/ets/ProxyCacheUtils.ets diff --git a/OhosVideoCache/library/src/main/ets/Source.ts b/OhosVideoCache/library/src/main/ets/Source.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/Source.ts rename to OhosVideoCache/library/src/main/ets/Source.ets diff --git a/OhosVideoCache/library/src/main/ets/SourceInfo.ts b/OhosVideoCache/library/src/main/ets/SourceInfo.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/SourceInfo.ts rename to OhosVideoCache/library/src/main/ets/SourceInfo.ets diff --git a/OhosVideoCache/library/src/main/ets/StorageUtils.ts b/OhosVideoCache/library/src/main/ets/StorageUtils.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/StorageUtils.ts rename to OhosVideoCache/library/src/main/ets/StorageUtils.ets diff --git a/OhosVideoCache/library/src/main/ets/bean/CacheFileBean.ts b/OhosVideoCache/library/src/main/ets/bean/CacheFileBean.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/bean/CacheFileBean.ts rename to OhosVideoCache/library/src/main/ets/bean/CacheFileBean.ets diff --git a/OhosVideoCache/library/src/main/ets/bean/MessageCallBackBean.ts b/OhosVideoCache/library/src/main/ets/bean/MessageCallBackBean.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/bean/MessageCallBackBean.ts rename to OhosVideoCache/library/src/main/ets/bean/MessageCallBackBean.ets diff --git a/OhosVideoCache/library/src/main/ets/bean/MyHeader.ts b/OhosVideoCache/library/src/main/ets/bean/MyHeader.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/bean/MyHeader.ts rename to OhosVideoCache/library/src/main/ets/bean/MyHeader.ets diff --git a/OhosVideoCache/library/src/main/ets/bean/ProgressValue.ts b/OhosVideoCache/library/src/main/ets/bean/ProgressValue.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/bean/ProgressValue.ts rename to OhosVideoCache/library/src/main/ets/bean/ProgressValue.ets diff --git a/OhosVideoCache/library/src/main/ets/constant/VideoCacheConstant.ts b/OhosVideoCache/library/src/main/ets/constant/VideoCacheConstant.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/constant/VideoCacheConstant.ts rename to OhosVideoCache/library/src/main/ets/constant/VideoCacheConstant.ets diff --git a/OhosVideoCache/library/src/main/ets/file/DiskUsage.ts b/OhosVideoCache/library/src/main/ets/file/DiskUsage.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/file/DiskUsage.ts rename to OhosVideoCache/library/src/main/ets/file/DiskUsage.ets diff --git a/OhosVideoCache/library/src/main/ets/file/FileCache.ts b/OhosVideoCache/library/src/main/ets/file/FileCache.ets similarity index 97% rename from OhosVideoCache/library/src/main/ets/file/FileCache.ts rename to OhosVideoCache/library/src/main/ets/file/FileCache.ets index 974f1897250fd85711ba3ad19628b228839deffe..279b7c5d8ab0a7574037c37c1360258bc30f50a8 100644 --- a/OhosVideoCache/library/src/main/ets/file/FileCache.ts +++ b/OhosVideoCache/library/src/main/ets/file/FileCache.ets @@ -75,6 +75,9 @@ export default class FileCache implements Cache { return; } self.isRenamedEnd = false; + if(!self.dataFile){ + return; + } fs.fsyncSync(self.dataFile.fd); fs.closeSync(self.dataFile.fd); fs.renameSync(this.tempFilePath, this.trueFilePath); @@ -122,6 +125,9 @@ export default class FileCache implements Cache { }) }) } + if(!this.dataFile) { + return; + } emitter.off(VideoCacheConstant.RENAME_FINISH_ID) fs.fsyncSync(this.dataFile.fd) fs.closeSync(this.dataFile.fd) @@ -141,9 +147,8 @@ export default class FileCache implements Cache { return } - this.dataFile?.write(fileData).then(() => { - fs.fsync(this.dataFile?.fd) - }) + this.dataFile?.writeSync(fileData); + fs.fsyncSync(this.dataFile?.fd); } catch (e) { let format = `Error writing ${length} bytes to ${this.tempFilePath}from buffer with size ${fileData.byteLength},reason is : ${e.message}`; diff --git a/OhosVideoCache/library/src/main/ets/file/FileNameGenerator.ts b/OhosVideoCache/library/src/main/ets/file/FileNameGenerator.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/file/FileNameGenerator.ts rename to OhosVideoCache/library/src/main/ets/file/FileNameGenerator.ets diff --git a/OhosVideoCache/library/src/main/ets/file/Files.ts b/OhosVideoCache/library/src/main/ets/file/Files.ets similarity index 99% rename from OhosVideoCache/library/src/main/ets/file/Files.ts rename to OhosVideoCache/library/src/main/ets/file/Files.ets index d3509b57089933c7ceafc4d558fecf51d7f266f9..01886968ce235b852a2d581f137178ebfc921d24 100644 --- a/OhosVideoCache/library/src/main/ets/file/Files.ts +++ b/OhosVideoCache/library/src/main/ets/file/Files.ets @@ -1,4 +1,3 @@ -// @ts-nocheck /* * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/OhosVideoCache/library/src/main/ets/file/ListFileOption.ts b/OhosVideoCache/library/src/main/ets/file/ListFileOption.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/file/ListFileOption.ts rename to OhosVideoCache/library/src/main/ets/file/ListFileOption.ets diff --git a/OhosVideoCache/library/src/main/ets/file/LruDiskUsage.ts b/OhosVideoCache/library/src/main/ets/file/LruDiskUsage.ets similarity index 99% rename from OhosVideoCache/library/src/main/ets/file/LruDiskUsage.ts rename to OhosVideoCache/library/src/main/ets/file/LruDiskUsage.ets index 8a1de4e14f51e0433b443ff2fa9161888a62ae3e..adb1d030bf2d23fd810046073e4720f7e20b1a25 100644 --- a/OhosVideoCache/library/src/main/ets/file/LruDiskUsage.ts +++ b/OhosVideoCache/library/src/main/ets/file/LruDiskUsage.ets @@ -1,4 +1,3 @@ -// @ts-nocheck /* * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/OhosVideoCache/library/src/main/ets/file/Md5FileNameGenerator.ts b/OhosVideoCache/library/src/main/ets/file/Md5FileNameGenerator.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/file/Md5FileNameGenerator.ts rename to OhosVideoCache/library/src/main/ets/file/Md5FileNameGenerator.ets diff --git a/OhosVideoCache/library/src/main/ets/file/TotalCountLruDiskUsage.ts b/OhosVideoCache/library/src/main/ets/file/TotalCountLruDiskUsage.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/file/TotalCountLruDiskUsage.ts rename to OhosVideoCache/library/src/main/ets/file/TotalCountLruDiskUsage.ets diff --git a/OhosVideoCache/library/src/main/ets/file/TotalSizeLruDiskUsage.ts b/OhosVideoCache/library/src/main/ets/file/TotalSizeLruDiskUsage.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/file/TotalSizeLruDiskUsage.ts rename to OhosVideoCache/library/src/main/ets/file/TotalSizeLruDiskUsage.ets diff --git a/OhosVideoCache/library/src/main/ets/file/UnlimitedDiskUsage.ts b/OhosVideoCache/library/src/main/ets/file/UnlimitedDiskUsage.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/file/UnlimitedDiskUsage.ts rename to OhosVideoCache/library/src/main/ets/file/UnlimitedDiskUsage.ets diff --git a/OhosVideoCache/library/src/main/ets/headers/EmptyHeadersInjector.ts b/OhosVideoCache/library/src/main/ets/headers/EmptyHeadersInjector.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/headers/EmptyHeadersInjector.ts rename to OhosVideoCache/library/src/main/ets/headers/EmptyHeadersInjector.ets diff --git a/OhosVideoCache/library/src/main/ets/headers/HeaderInjector.ts b/OhosVideoCache/library/src/main/ets/headers/HeaderInjector.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/headers/HeaderInjector.ts rename to OhosVideoCache/library/src/main/ets/headers/HeaderInjector.ets diff --git a/OhosVideoCache/library/src/main/ets/interfaces/AutoCloseable.ts b/OhosVideoCache/library/src/main/ets/interfaces/AutoCloseable.ets similarity index 97% rename from OhosVideoCache/library/src/main/ets/interfaces/AutoCloseable.ts rename to OhosVideoCache/library/src/main/ets/interfaces/AutoCloseable.ets index e9689215f676a1363b65865ee6251a5d17fdd3d2..fac2918dcecf7c27290b00eecc9a6c60c5112cf6 100644 --- a/OhosVideoCache/library/src/main/ets/interfaces/AutoCloseable.ts +++ b/OhosVideoCache/library/src/main/ets/interfaces/AutoCloseable.ets @@ -14,5 +14,5 @@ */ export default interface AutoCloseable { - close() + close(): void; } \ No newline at end of file diff --git a/OhosVideoCache/library/src/main/ets/interfaces/Callable.ts b/OhosVideoCache/library/src/main/ets/interfaces/Callable.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/interfaces/Callable.ts rename to OhosVideoCache/library/src/main/ets/interfaces/Callable.ets diff --git a/OhosVideoCache/library/src/main/ets/interfaces/Closeable.ts b/OhosVideoCache/library/src/main/ets/interfaces/Closeable.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/interfaces/Closeable.ts rename to OhosVideoCache/library/src/main/ets/interfaces/Closeable.ets diff --git a/OhosVideoCache/library/src/main/ets/interfaces/DataBackListener.ts b/OhosVideoCache/library/src/main/ets/interfaces/DataBackListener.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/interfaces/DataBackListener.ts rename to OhosVideoCache/library/src/main/ets/interfaces/DataBackListener.ets diff --git a/OhosVideoCache/library/src/main/ets/sourcestorage/DatabaseSourceInfoStorage.ts b/OhosVideoCache/library/src/main/ets/sourcestorage/DatabaseSourceInfoStorage.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/sourcestorage/DatabaseSourceInfoStorage.ts rename to OhosVideoCache/library/src/main/ets/sourcestorage/DatabaseSourceInfoStorage.ets diff --git a/OhosVideoCache/library/src/main/ets/sourcestorage/NoSourceInfoStorage.ts b/OhosVideoCache/library/src/main/ets/sourcestorage/NoSourceInfoStorage.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/sourcestorage/NoSourceInfoStorage.ts rename to OhosVideoCache/library/src/main/ets/sourcestorage/NoSourceInfoStorage.ets diff --git a/OhosVideoCache/library/src/main/ets/sourcestorage/SourceInfoStorage.ts b/OhosVideoCache/library/src/main/ets/sourcestorage/SourceInfoStorage.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/sourcestorage/SourceInfoStorage.ts rename to OhosVideoCache/library/src/main/ets/sourcestorage/SourceInfoStorage.ets diff --git a/OhosVideoCache/library/src/main/ets/sourcestorage/SourceInfoStorageFactory.ts b/OhosVideoCache/library/src/main/ets/sourcestorage/SourceInfoStorageFactory.ets similarity index 100% rename from OhosVideoCache/library/src/main/ets/sourcestorage/SourceInfoStorageFactory.ts rename to OhosVideoCache/library/src/main/ets/sourcestorage/SourceInfoStorageFactory.ets diff --git a/OhosVideoCache/oh-package.json5 b/OhosVideoCache/oh-package.json5 index 0cea5eca1e29c37667fa32f9695e83014ed7e3ae..374dcd0f158da3e5e1ad2dbe75aa5e8090587fbb 100644 --- a/OhosVideoCache/oh-package.json5 +++ b/OhosVideoCache/oh-package.json5 @@ -1,6 +1,6 @@ { "name": "ohosvideocache", - "version": "1.0.3-rc.1", + "version": "1.0.3-rc.2", "description": "Please describe the basic information.", "main": "", "author": "",