Skip to content

Commit 5dbcbb9

Browse files
committed
standard.js style
1 parent c5c2b52 commit 5dbcbb9

File tree

4 files changed

+609
-613
lines changed

4 files changed

+609
-613
lines changed

file.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import Blob from './index.js';
1+
import Blob from './index.js'
22

33
const _File = class File extends Blob {
4-
#lastModified = 0;
5-
#name = '';
4+
#lastModified = 0
5+
#name = ''
66

77
/**
88
* @param {*[]} fileBits
99
* @param {string} fileName
1010
* @param {{lastModified?: number, type?: string}} options
1111
*/// @ts-ignore
12-
constructor(fileBits, fileName, options = {}) {
12+
constructor (fileBits, fileName, options = {}) {
1313
if (arguments.length < 2) {
14-
throw new TypeError(`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`);
14+
throw new TypeError(`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`)
1515
}
16-
super(fileBits, options);
16+
super(fileBits, options)
1717

18-
if (options === null) options = {};
18+
if (options === null) options = {}
1919

2020
// Simulate WebIDL type casting for NaN value in lastModified option.
21-
const lastModified = options.lastModified === undefined ? Date.now() : Number(options.lastModified);
21+
const lastModified = options.lastModified === undefined ? Date.now() : Number(options.lastModified)
2222
if (!Number.isNaN(lastModified)) {
23-
this.#lastModified = lastModified;
23+
this.#lastModified = lastModified
2424
}
2525

26-
this.#name = String(fileName);
26+
this.#name = String(fileName)
2727
}
2828

29-
get name() {
30-
return this.#name;
29+
get name () {
30+
return this.#name
3131
}
3232

33-
get lastModified() {
34-
return this.#lastModified;
33+
get lastModified () {
34+
return this.#lastModified
3535
}
3636

37-
get [Symbol.toStringTag]() {
38-
return "File";
37+
get [Symbol.toStringTag] () {
38+
return 'File'
3939
}
4040
}
4141

4242
/** @type {typeof globalThis.File} */// @ts-ignore
43-
export const File = _File;
44-
export default File;
43+
export const File = _File
44+
export default File

from.js

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,57 @@
1-
import {statSync, createReadStream, promises as fs} from 'node:fs';
2-
import {basename} from 'node:path';
3-
import {MessageChannel} from 'node:worker_threads';
1+
import { statSync, createReadStream, promises as fs } from 'node:fs'
2+
import { basename } from 'node:path'
3+
import { MessageChannel } from 'node:worker_threads'
44

5-
import File from './file.js';
6-
import Blob from './index.js';
5+
import File from './file.js'
6+
import Blob from './index.js'
77

8-
const {stat} = fs;
8+
const { stat } = fs
99

1010
const DOMException = globalThis.DOMException || (() => {
11-
const port = new MessageChannel().port1
12-
const ab = new ArrayBuffer(0)
13-
try { port.postMessage(ab, [ab, ab]) }
14-
catch (err) { return err.constructor }
11+
const port = new MessageChannel().port1
12+
const ab = new ArrayBuffer(0)
13+
try { port.postMessage(ab, [ab, ab]) } catch (err) { return err.constructor }
1514
})()
1615

1716
/**
1817
* @param {string} path filepath on the disk
1918
* @param {string} [type] mimetype to use
2019
*/
21-
const blobFromSync = (path, type) => fromBlob(statSync(path), path, type);
20+
const blobFromSync = (path, type) => fromBlob(statSync(path), path, type)
2221

2322
/**
2423
* @param {string} path filepath on the disk
2524
* @param {string} [type] mimetype to use
2625
*/
27-
const blobFrom = (path, type) => stat(path).then(stat => fromBlob(stat, path, type));
26+
const blobFrom = (path, type) => stat(path).then(stat => fromBlob(stat, path, type))
2827

2928
/**
3029
* @param {string} path filepath on the disk
3130
* @param {string} [type] mimetype to use
3231
*/
33-
const fileFrom = (path, type) => stat(path).then(stat => fromFile(stat, path, type));
32+
const fileFrom = (path, type) => stat(path).then(stat => fromFile(stat, path, type))
3433

3534
/**
3635
* @param {string} path filepath on the disk
3736
* @param {string} [type] mimetype to use
3837
*/
39-
const fileFromSync = (path, type) => fromFile(statSync(path), path, type);
38+
const fileFromSync = (path, type) => fromFile(statSync(path), path, type)
4039

4140
// @ts-ignore
4241
const fromBlob = (stat, path, type = '') => new Blob([new BlobDataItem({
43-
path,
44-
size: stat.size,
45-
lastModified: stat.mtimeMs,
46-
start: 0
47-
})], {type});
42+
path,
43+
size: stat.size,
44+
lastModified: stat.mtimeMs,
45+
start: 0
46+
})], { type })
4847

4948
// @ts-ignore
5049
const fromFile = (stat, path, type = '') => new File([new BlobDataItem({
51-
path,
52-
size: stat.size,
53-
lastModified: stat.mtimeMs,
54-
start: 0
55-
})], basename(path), { type, lastModified: stat.mtimeMs });
50+
path,
51+
size: stat.size,
52+
lastModified: stat.mtimeMs,
53+
start: 0
54+
})], basename(path), { type, lastModified: stat.mtimeMs })
5655

5756
/**
5857
* This is a blob backed up by a file on the disk
@@ -62,44 +61,44 @@ const fromFile = (stat, path, type = '') => new File([new BlobDataItem({
6261
* @private
6362
*/
6463
class BlobDataItem {
65-
#path;
66-
#start;
64+
#path
65+
#start
6766

68-
constructor(options) {
69-
this.#path = options.path;
70-
this.#start = options.start;
71-
this.size = options.size;
72-
this.lastModified = options.lastModified
73-
}
67+
constructor (options) {
68+
this.#path = options.path
69+
this.#start = options.start
70+
this.size = options.size
71+
this.lastModified = options.lastModified
72+
}
7473

75-
/**
76-
* Slicing arguments is first validated and formatted
77-
* to not be out of range by Blob.prototype.slice
78-
*/
79-
slice(start, end) {
80-
return new BlobDataItem({
81-
path: this.#path,
82-
lastModified: this.lastModified,
83-
size: end - start,
84-
start
85-
});
86-
}
74+
/**
75+
* Slicing arguments is first validated and formatted
76+
* to not be out of range by Blob.prototype.slice
77+
*/
78+
slice (start, end) {
79+
return new BlobDataItem({
80+
path: this.#path,
81+
lastModified: this.lastModified,
82+
size: end - start,
83+
start
84+
})
85+
}
8786

88-
async * stream() {
89-
const {mtimeMs} = await stat(this.#path)
90-
if (mtimeMs > this.lastModified) {
91-
throw new DOMException('The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.', 'NotReadableError');
92-
}
93-
yield * createReadStream(this.#path, {
94-
start: this.#start,
95-
end: this.#start + this.size - 1
96-
});
97-
}
87+
async * stream () {
88+
const { mtimeMs } = await stat(this.#path)
89+
if (mtimeMs > this.lastModified) {
90+
throw new DOMException('The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.', 'NotReadableError')
91+
}
92+
yield * createReadStream(this.#path, {
93+
start: this.#start,
94+
end: this.#start + this.size - 1
95+
})
96+
}
9897

99-
get [Symbol.toStringTag]() {
100-
return 'Blob';
101-
}
98+
get [Symbol.toStringTag] () {
99+
return 'Blob'
100+
}
102101
}
103102

104-
export default blobFromSync;
105-
export {File, Blob, blobFrom, blobFromSync, fileFrom, fileFromSync};
103+
export default blobFromSync
104+
export { File, Blob, blobFrom, blobFromSync, fileFrom, fileFromSync }

0 commit comments

Comments
 (0)