Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp #83

Merged
merged 18 commits into from
May 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
import from fs/promise instead
  • Loading branch information
jimmywarting committed Apr 26, 2021
commit 85105af65ed82e3f6dc5a15fcb8deac772211b62
11 changes: 5 additions & 6 deletions from.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {statSync, createReadStream, promises as fs} from 'fs';
import {statSync, createReadStream} from 'fs';
import {stat} from 'fs/promises';
import DOMException from 'domexception';
import Blob from './index.js';

const {stat} = fs;

/**
* @param {string} path filepath on the disk
* @returns {Blob}
Expand All @@ -19,7 +18,7 @@ const blobFromSync = path => from(statSync(path), path);
const from = (stat, path) => new Blob([new BlobDataItem({
path,
size: stat.size,
lastModified: Number(stat.mtime),
lastModified: stat.mtimeMs,
start: 0
})]);

Expand Down Expand Up @@ -55,8 +54,8 @@ class BlobDataItem {
}

async * stream() {
const metadata = await stat(this.#path)
if (metadata.mtime > this.lastModified) {
const {mtimeMs} = await stat(this.#path)
if (mtimeMs > this.lastModified) {
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');
jimmywarting marked this conversation as resolved.
Show resolved Hide resolved
}
if (this.size) {
Expand Down