BREAKING CHANGE FileInfo.len renamed to FileName.size (#4338)

This commit is contained in:
dubiousjim 2020-03-14 22:57:42 -04:00 committed by GitHub
parent 0df9823cba
commit 6cc40b0865
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 26 deletions

View file

@ -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;

View file

@ -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. */

View file

@ -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;

View file

@ -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