file-fetch
Advanced tools
Comparing version 1.6.1 to 1.7.0
12
index.js
@@ -14,2 +14,3 @@ /* global URL */ | ||
const access = promisify(fs.access) | ||
const stat = promisify(fs.stat) | ||
@@ -33,2 +34,10 @@ function decodeIRI (iri, baseDir, baseURL) { | ||
async function silentFileSize (pathname) { | ||
try { | ||
return (await stat(pathname)).size | ||
} catch (err) { | ||
return null | ||
} | ||
} | ||
function response (status, body, headers) { | ||
@@ -53,2 +62,4 @@ return { | ||
if (method === 'GET') { | ||
const size = await silentFileSize(pathname) | ||
return new Promise((resolve) => { | ||
@@ -63,2 +74,3 @@ const stream = fs.createReadStream(pathname) | ||
resolve(response(200, stream, { | ||
'content-length': size.toString(), | ||
'content-type': contentTypeLookup(extension) || contentType(extension) | ||
@@ -65,0 +77,0 @@ })) |
{ | ||
"name": "file-fetch", | ||
"version": "1.6.1", | ||
"version": "1.7.0", | ||
"description": "fetch for read and write access to the local file system", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -66,2 +66,8 @@ const fs = require('fs') | ||
it('should set the content-length header', async () => { | ||
const res = await fileFetch('file://' + path.join(__dirname, 'support/file.txt')) | ||
assert.strictEqual(res.headers.get('content-length'), '4') | ||
}) | ||
it('should read the file content with method GET', async () => { | ||
@@ -68,0 +74,0 @@ const res = await fileFetch('file://' + path.join(__dirname, 'support/file.txt'), { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18278
487