From 795c1bac12f55bc8d6e06f1e0e5d5399ff1bf407 Mon Sep 17 00:00:00 2001 From: hugoalh Date: Fri, 3 Jan 2025 17:20:44 +0800 Subject: [PATCH] Disallow write encrypted file with append mode --- README.md | 4 ++-- jsr.jsonc | 2 +- mod.ts | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 12fe9ac..a79815d 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ An ES (JavaScript & TypeScript) module to provide an easier symmetric crypto. encryptFile(...filesPath: (string | URL)[]): Promise; readEncryptedFile(filePath: string | URL, options?: Deno.ReadFileOptions): Promise; readEncryptedTextFile(filePath: string | URL, options?: Deno.ReadFileOptions): Promise; - writeEncryptedFile(filePath: string | URL, data: Uint8Array, options?: Deno.WriteFileOptions): Promise; - writeEncryptedTextFile(filePath: string | URL, data: string, options?: Deno.WriteFileOptions): Promise; + writeEncryptedFile(filePath: string | URL, data: Uint8Array, options?: Omit): Promise; + writeEncryptedTextFile(filePath: string | URL, data: string, options?: Omit): Promise; } ``` - ```ts diff --git a/jsr.jsonc b/jsr.jsonc index a88506e..29ca053 100644 --- a/jsr.jsonc +++ b/jsr.jsonc @@ -1,7 +1,7 @@ { "$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json", "name": "@hugoalh/symmetric-crypto", - "version": "4.2.0", + "version": "4.2.1", "exports": { ".": "./mod.ts" }, diff --git a/mod.ts b/mod.ts index 1056fcf..d409716 100644 --- a/mod.ts +++ b/mod.ts @@ -297,11 +297,14 @@ export class SymmetricCryptor { * > - *Resources* * @param {string | URL} filePath Path of the file. * @param {Uint8Array} data Data of the file. - * @param {Deno.WriteFileOptions} [options={}] Options. + * @param {Omit} [options={}] Options. * @returns {Promise} */ - async writeEncryptedFile(filePath: string | URL, data: Uint8Array, options?: Deno.WriteFileOptions): Promise { - await Deno.writeFile(filePath, await this.#encrypt(data), options); + async writeEncryptedFile(filePath: string | URL, data: Uint8Array, options?: Omit): Promise { + await Deno.writeFile(filePath, await this.#encrypt(data), { + ...options, + append: false + }); return this; } /** @@ -313,10 +316,10 @@ export class SymmetricCryptor { * > - *Resources* * @param {string | URL} filePath Path of the file. * @param {string} data Text data of the file. - * @param {Deno.WriteFileOptions} [options={}] Options. + * @param {Omit} [options={}] Options. * @returns {Promise} */ - async writeEncryptedTextFile(filePath: string | URL, data: string, options?: Deno.WriteFileOptions): Promise { + async writeEncryptedTextFile(filePath: string | URL, data: string, options?: Omit): Promise { await this.writeEncryptedFile(filePath, new TextEncoder().encode(data), options); return this; }