diff --git a/cli/js/file_info.ts b/cli/js/file_info.ts index e7ac646fbf..827239769c 100644 --- a/cli/js/file_info.ts +++ b/cli/js/file_info.ts @@ -3,7 +3,7 @@ import { StatResponse } from "./ops/fs/stat.ts"; import { build } from "./build.ts"; export interface FileInfo { - len: number; + size: number; modified: number | null; accessed: number | null; created: number | null; @@ -26,7 +26,7 @@ export interface FileInfo { export class FileInfoImpl implements FileInfo { private readonly _isFile: boolean; private readonly _isSymlink: boolean; - len: number; + size: number; modified: number | null; accessed: number | null; created: number | null; @@ -64,7 +64,7 @@ export class FileInfoImpl implements FileInfo { this._isFile = this._res.isFile; this._isSymlink = this._res.isSymlink; - this.len = this._res.len; + this.size = this._res.size; this.modified = modified ? modified : null; this.accessed = accessed ? accessed : null; this.created = created ? created : null; diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index 751e4452b3..daae8b09d7 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -661,7 +661,7 @@ declare namespace Deno { append?: boolean; /** Sets the option for truncating a previous file. If a file is * successfully opened with this option set it will truncate the file to `0` - * length if it already exists. The file must be opened with write access + * size if it already exists. The file must be opened with write access * for truncate to work. */ truncate?: boolean; /** Sets the option to allow creating a new file, if one doesn't already @@ -1058,16 +1058,12 @@ declare namespace Deno { // @url js/file_info.d.ts - /** UNSTABLE: 'len' maybe should be 'length' or 'size'. - * - * A FileInfo describes a file and is returned by `stat`, `lstat`, + /** A FileInfo describes a file and is returned by `stat`, `lstat`, * `statSync`, `lstatSync`. A list of FileInfo is returned by `readdir`, * `readdirSync`. */ export interface FileInfo { - /** **UNSTABLE**: `.len` maybe should be `.length` or `.size`. - * - * The size of the file, in bytes. */ - len: number; + /** The size of the file, in bytes. */ + size: number; /** The last modification time of the file. This corresponds to the `mtime` * field from `stat` on Linux/Mac OS and `ftLastWriteTime` on Windows. This * may not be available on all platforms. */ diff --git a/cli/js/ops/fs/stat.ts b/cli/js/ops/fs/stat.ts index 032cc97ee2..20ca3e6b16 100644 --- a/cli/js/ops/fs/stat.ts +++ b/cli/js/ops/fs/stat.ts @@ -5,7 +5,7 @@ import { FileInfo, FileInfoImpl } from "../../file_info.ts"; export interface StatResponse { isFile: boolean; isSymlink: boolean; - len: number; + size: number; modified: number; accessed: number; created: number; diff --git a/cli/js/tests/files_test.ts b/cli/js/tests/files_test.ts index 49fecabe0d..29e2812d48 100644 --- a/cli/js/tests/files_test.ts +++ b/cli/js/tests/files_test.ts @@ -19,7 +19,7 @@ unitTest({ perms: { read: true } }, async function filesCopyToStdout(): Promise< const file = await Deno.open(filename); assert(file.rid > 2); const bytesWritten = await Deno.copy(Deno.stdout, file); - const fileSize = Deno.statSync(filename).len; + const fileSize = Deno.statSync(filename).size; assertEquals(bytesWritten, fileSize); console.log("bytes written", bytesWritten); file.close(); @@ -234,12 +234,12 @@ unitTest( const f = await Deno.create(filename); let fileInfo = Deno.statSync(filename); assert(fileInfo.isFile()); - assert(fileInfo.len === 0); + assert(fileInfo.size === 0); const enc = new TextEncoder(); const data = enc.encode("Hello"); await f.write(data); fileInfo = Deno.statSync(filename); - assert(fileInfo.len === 5); + assert(fileInfo.size === 5); f.close(); // TODO: test different modes @@ -258,11 +258,11 @@ unitTest( // assert file was created let fileInfo = Deno.statSync(filename); assert(fileInfo.isFile()); - assertEquals(fileInfo.len, 0); + assertEquals(fileInfo.size, 0); // write some data await file.write(data); fileInfo = Deno.statSync(filename); - assertEquals(fileInfo.len, 13); + assertEquals(fileInfo.size, 13); // assert we can't read from file let thrown = false; try { @@ -277,7 +277,7 @@ unitTest( // assert that existing file is truncated on open file = await Deno.open(filename, "w"); file.close(); - const fileSize = Deno.statSync(filename).len; + const fileSize = Deno.statSync(filename).size; assertEquals(fileSize, 0); await Deno.remove(tempDir, { recursive: true }); } @@ -296,11 +296,11 @@ unitTest( // assert file was created let fileInfo = Deno.statSync(filename); assert(fileInfo.isFile()); - assertEquals(fileInfo.len, 0); + assertEquals(fileInfo.size, 0); // write some data await file.write(data); fileInfo = Deno.statSync(filename); - assertEquals(fileInfo.len, 13); + assertEquals(fileInfo.size, 13); const buf = new Uint8Array(20); // seeking from beginning of a file diff --git a/cli/ops/fs.rs b/cli/ops/fs.rs index 01ce548bab..6c978d51cf 100644 --- a/cli/ops/fs.rs +++ b/cli/ops/fs.rs @@ -431,7 +431,7 @@ fn op_copy_file( return Err(OpError::not_found("File not found".to_string())); } - // returns length of from as u64 (we ignore) + // returns size of from as u64 (we ignore) fs::copy(&from, &to)?; Ok(json!({})) }) @@ -469,7 +469,7 @@ fn get_stat_json( let mut json_val = json!({ "isFile": metadata.is_file(), "isSymlink": metadata.file_type().is_symlink(), - "len": metadata.len(), + "size": metadata.len(), // In seconds. Available on both Unix or Windows. "modified":to_seconds!(metadata.modified()), "accessed":to_seconds!(metadata.accessed()), diff --git a/std/archive/tar.ts b/std/archive/tar.ts index 33a9ae0974..2680bcff25 100644 --- a/std/archive/tar.ts +++ b/std/archive/tar.ts @@ -334,7 +334,7 @@ export class Tar { ); } - const fileSize = info?.len ?? opts.contentSize; + const fileSize = info?.size ?? opts.contentSize; assert(fileSize != null, "fileSize must be set"); const tarData: TarDataWithSource = { fileName, diff --git a/std/http/file_server.ts b/std/http/file_server.ts index 28eaef44d5..a259acb3c4 100755 --- a/std/http/file_server.ts +++ b/std/http/file_server.ts @@ -102,7 +102,7 @@ async function serveFile( ): Promise { const [file, fileInfo] = await Promise.all([open(filePath), stat(filePath)]); const headers = new Headers(); - headers.set("content-length", fileInfo.len.toString()); + headers.set("content-length", fileInfo.size.toString()); headers.set("content-type", "text/plain; charset=utf-8"); const res = { @@ -135,7 +135,7 @@ async function serveDir( } catch (e) {} listEntry.push({ mode: modeToString(fileInfo.isDirectory(), mode), - size: fileInfo.isFile() ? fileLenToString(fileInfo.len) : "", + size: fileInfo.isFile() ? fileLenToString(fileInfo.size) : "", name: fileInfo.name ?? "", url: fileUrl }); diff --git a/std/node/_fs/_fs_dirent_test.ts b/std/node/_fs/_fs_dirent_test.ts index 6fe0f4020b..36091d3e13 100644 --- a/std/node/_fs/_fs_dirent_test.ts +++ b/std/node/_fs/_fs_dirent_test.ts @@ -3,7 +3,7 @@ import { assert, assertEquals, assertThrows } from "../../testing/asserts.ts"; import Dirent from "./_fs_dirent.ts"; class FileInfoMock implements Deno.FileInfo { - len = -1; + size = -1; modified = -1; accessed = -1; created = -1;