(
key: string,
content: ArrayBuffer,
mtime: number,
ctime: number
)
| 296 | } |
| 297 | |
| 298 | async writeFile( |
| 299 | key: string, |
| 300 | content: ArrayBuffer, |
| 301 | mtime: number, |
| 302 | ctime: number |
| 303 | ): Promise<Entity> { |
| 304 | if (!this.hasCacheMap) { |
| 305 | throw new Error("You have to build the cacheMap firstly for readFile"); |
| 306 | } |
| 307 | let keyEnc = this.cacheMapOrigToEnc[key]; |
| 308 | if (keyEnc === undefined) { |
| 309 | if (this.isPasswordEmpty()) { |
| 310 | keyEnc = key; |
| 311 | } else { |
| 312 | keyEnc = await this._encryptName(key); |
| 313 | } |
| 314 | this.cacheMapOrigToEnc[key] = keyEnc; |
| 315 | } |
| 316 | |
| 317 | if (this.isPasswordEmpty()) { |
| 318 | const innerEntity = await this.innerFs.writeFile( |
| 319 | keyEnc, |
| 320 | content, |
| 321 | mtime, |
| 322 | ctime |
| 323 | ); |
| 324 | return copyEntityAndCopyKeyEncSizeEnc(innerEntity); |
| 325 | } else { |
| 326 | const contentEnc = await this._encryptContent(content); |
| 327 | const innerEntity = await this.innerFs.writeFile( |
| 328 | keyEnc, |
| 329 | contentEnc, |
| 330 | mtime, |
| 331 | ctime |
| 332 | ); |
| 333 | return { |
| 334 | key: key, |
| 335 | keyRaw: innerEntity.keyRaw, |
| 336 | keyEnc: innerEntity.key!, |
| 337 | mtimeCli: innerEntity.mtimeCli, |
| 338 | mtimeSvr: innerEntity.mtimeSvr, |
| 339 | size: undefined, |
| 340 | sizeEnc: innerEntity.size!, |
| 341 | sizeRaw: innerEntity.sizeRaw, |
| 342 | hash: undefined, |
| 343 | synthesizedFolder: innerEntity.synthesizedFolder, |
| 344 | }; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | async readFile(key: string): Promise<ArrayBuffer> { |
| 349 | if (!this.hasCacheMap) { |
no test coverage detected