Skip to content

Commit

Permalink
Disallow write encrypted file with append mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoalh committed Jan 3, 2025
1 parent 075f810 commit 795c1ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ An ES (JavaScript & TypeScript) module to provide an easier symmetric crypto.
encryptFile(...filesPath: (string | URL)[]): Promise<this>;
readEncryptedFile(filePath: string | URL, options?: Deno.ReadFileOptions): Promise<Uint8Array>;
readEncryptedTextFile(filePath: string | URL, options?: Deno.ReadFileOptions): Promise<string>;
writeEncryptedFile(filePath: string | URL, data: Uint8Array, options?: Deno.WriteFileOptions): Promise<this>;
writeEncryptedTextFile(filePath: string | URL, data: string, options?: Deno.WriteFileOptions): Promise<this>;
writeEncryptedFile(filePath: string | URL, data: Uint8Array, options?: Omit<Deno.WriteFileOptions, "append">): Promise<this>;
writeEncryptedTextFile(filePath: string | URL, data: string, options?: Omit<Deno.WriteFileOptions, "append">): Promise<this>;
}
```
- ```ts
Expand Down
2 changes: 1 addition & 1 deletion jsr.jsonc
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
13 changes: 8 additions & 5 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Deno.WriteFileOptions, "append">} [options={}] Options.
* @returns {Promise<this>}
*/
async writeEncryptedFile(filePath: string | URL, data: Uint8Array, options?: Deno.WriteFileOptions): Promise<this> {
await Deno.writeFile(filePath, await this.#encrypt(data), options);
async writeEncryptedFile(filePath: string | URL, data: Uint8Array, options?: Omit<Deno.WriteFileOptions, "append">): Promise<this> {
await Deno.writeFile(filePath, await this.#encrypt(data), {
...options,
append: false
});
return this;
}
/**
Expand All @@ -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<Deno.WriteFileOptions, "append">} [options={}] Options.
* @returns {Promise<this>}
*/
async writeEncryptedTextFile(filePath: string | URL, data: string, options?: Deno.WriteFileOptions): Promise<this> {
async writeEncryptedTextFile(filePath: string | URL, data: string, options?: Omit<Deno.WriteFileOptions, "append">): Promise<this> {
await this.writeEncryptedFile(filePath, new TextEncoder().encode(data), options);
return this;
}
Expand Down

0 comments on commit 795c1ba

Please sign in to comment.