file-fetch
Advanced tools
Comparing version 1.3.0 to 1.3.1
18
index.js
@@ -9,2 +9,18 @@ const fs = require('fs') | ||
function decodeIRI (iri) { | ||
// IRIs without file scheme are used directly | ||
if (!iri.startsWith('file:')) { | ||
return iri | ||
} | ||
const pathname = decodeURIComponent(new URL(iri).pathname) | ||
// remove the leading slash for IRIs with file scheme and relative path | ||
if (!iri.startsWith('file:/')) { | ||
return pathname.split('/').slice(1).join('/') | ||
} | ||
return pathname | ||
} | ||
function text (stream) { | ||
@@ -39,3 +55,3 @@ return new Promise((resolve, reject) => { | ||
const pathname = iri.startsWith('file:') ? decodeURIComponent(new URL(iri).pathname) : iri | ||
const pathname = decodeIRI(iri) | ||
@@ -42,0 +58,0 @@ if (options.method === 'GET') { |
{ | ||
"name": "file-fetch", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "fetch for read and write access to the local file system", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -85,2 +85,22 @@ const fs = require('fs') | ||
it('should read the file content with relative URL and method GET', () => { | ||
return fileFetch('file:./test/support/file.txt', { | ||
method: 'GET' | ||
}).then((res) => { | ||
return new Promise((resolve) => { | ||
let content = '' | ||
res.body.on('data', (chunk) => { | ||
content += chunk | ||
}) | ||
res.body.on('end', () => { | ||
assert.strictEqual(content, 'test') | ||
resolve() | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('should give a 404 path to non-existent file (method GET)', () => { | ||
@@ -87,0 +107,0 @@ return fileFetch('./test/support/nonexistent-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
10574
277