summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-rw-r--r--std/archive/tar.ts6
-rw-r--r--std/fs/walk_test.ts4
-rw-r--r--std/io/util.ts7
-rw-r--r--std/log/handlers.ts18
-rw-r--r--std/mime/multipart_test.ts4
5 files changed, 28 insertions, 11 deletions
diff --git a/std/archive/tar.ts b/std/archive/tar.ts
index 6bc2b92d0..699b982a9 100644
--- a/std/archive/tar.ts
+++ b/std/archive/tar.ts
@@ -39,15 +39,15 @@ const ustar = "ustar\u000000";
class FileReader implements Deno.Reader {
private file?: Deno.File;
- constructor(private filePath: string, private mode: Deno.OpenMode = "r") {}
+ constructor(private filePath: string) {}
public async read(p: Uint8Array): Promise<number | Deno.EOF> {
if (!this.file) {
- this.file = await Deno.open(this.filePath, this.mode);
+ this.file = await Deno.open(this.filePath, { read: true });
}
const res = await Deno.read(this.file.rid, p);
if (res === Deno.EOF) {
- await Deno.close(this.file.rid);
+ Deno.close(this.file.rid);
this.file = undefined;
}
return res;
diff --git a/std/fs/walk_test.ts b/std/fs/walk_test.ts
index 6a44f5514..b054db4cf 100644
--- a/std/fs/walk_test.ts
+++ b/std/fs/walk_test.ts
@@ -1,4 +1,4 @@
-const { cwd, chdir, makeTempDir, mkdir, open, symlink } = Deno;
+const { cwd, chdir, makeTempDir, mkdir, create, symlink } = Deno;
const { remove } = Deno;
import { walk, walkSync, WalkOptions, WalkEntry } from "./walk.ts";
import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
@@ -46,7 +46,7 @@ export async function walkArray(
}
export async function touch(path: string): Promise<void> {
- const f = await open(path, "w");
+ const f = await create(path);
f.close();
}
diff --git a/std/io/util.ts b/std/io/util.ts
index 28688ae91..18ddb4def 100644
--- a/std/io/util.ts
+++ b/std/io/util.ts
@@ -47,6 +47,11 @@ export async function tempFile(
`${dir}/${opts.prefix || ""}${r}${opts.postfix || ""}`
);
await mkdir(path.dirname(filepath), { recursive: true });
- const file = await open(filepath, "a");
+ const file = await open(filepath, {
+ create: true,
+ read: true,
+ write: true,
+ append: true,
+ });
return { file, filepath };
}
diff --git a/std/log/handlers.ts b/std/log/handlers.ts
index eea7f32ff..041f101ed 100644
--- a/std/log/handlers.ts
+++ b/std/log/handlers.ts
@@ -2,6 +2,7 @@
const { open, openSync, close, renameSync, statSync } = Deno;
type File = Deno.File;
type Writer = Deno.Writer;
+type OpenOptions = Deno.OpenOptions;
import { getLevelByName, LogLevel } from "./levels.ts";
import { LogRecord } from "./logger.ts";
import { red, yellow, blue, bold } from "../fmt/colors.ts";
@@ -101,6 +102,7 @@ export class FileHandler extends WriterHandler {
protected _file!: File;
protected _filename: string;
protected _mode: LogMode;
+ protected _openOptions: OpenOptions;
#encoder = new TextEncoder();
constructor(levelName: string, options: FileHandlerOptions) {
@@ -108,10 +110,17 @@ export class FileHandler extends WriterHandler {
this._filename = options.filename;
// default to append mode, write only
this._mode = options.mode ? options.mode : "a";
+ this._openOptions = {
+ createNew: this._mode === "x",
+ create: this._mode !== "x",
+ append: this._mode === "a",
+ truncate: this._mode !== "a",
+ write: true,
+ };
}
async setup(): Promise<void> {
- this._file = await open(this._filename, this._mode);
+ this._file = await open(this._filename, this._openOptions);
this._writer = this._file;
}
@@ -119,8 +128,9 @@ export class FileHandler extends WriterHandler {
Deno.writeSync(this._file.rid, this.#encoder.encode(msg + "\n"));
}
- async destroy(): Promise<void> {
- await this._file.close();
+ destroy(): Promise<void> {
+ this._file.close();
+ return Promise.resolve();
}
}
@@ -193,7 +203,7 @@ export class RotatingFileHandler extends FileHandler {
}
}
- this._file = openSync(this._filename, this._mode);
+ this._file = openSync(this._filename, this._openOptions);
this._writer = this._file;
}
}
diff --git a/std/mime/multipart_test.ts b/std/mime/multipart_test.ts
index aa3b7524e..c0cf012ec 100644
--- a/std/mime/multipart_test.ts
+++ b/std/mime/multipart_test.ts
@@ -93,7 +93,9 @@ test(async function multipartMultipartWriter(): Promise<void> {
const mw = new MultipartWriter(buf);
await mw.writeField("foo", "foo");
await mw.writeField("bar", "bar");
- const f = await open(path.resolve("./mime/testdata/sample.txt"), "r");
+ const f = await open(path.resolve("./mime/testdata/sample.txt"), {
+ read: true,
+ });
await mw.writeFile("file", "sample.txt", f);
await mw.close();
f.close();