1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 16:19:12 -05:00

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

View file

@ -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()),

View file

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

View file

@ -102,7 +102,7 @@ async function serveFile(
): Promise<Response> {
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
});

View file

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