Merge pull request #9323 from juncaixinchi/master

Get correct path in node_stream on windows platform( issue #9020)
This commit is contained in:
Tim van der Meij 2018-01-14 15:41:56 +01:00 committed by GitHub
commit 237bc2ef9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,8 @@ import {
} from '../shared/util';
import { validateRangeRequestCapabilities } from './network_utils';
const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
class PDFNodeStream {
constructor(source) {
this.source = source;
@ -362,8 +364,14 @@ class PDFNodeStreamRangeReader extends BaseRangeReader {
class PDFNodeStreamFsFullReader extends BaseFullReader {
constructor(stream) {
super(stream);
let path = decodeURI(this._url.path);
// Remove the extra slash to get right path from url like `file:///C:/`
if (fileUriRegex.test(this._url.href)) {
path = path.replace(/^\//, '');
}
fs.lstat(path, (error, stat) => {
if (error) {
this._errored = true;
@ -384,8 +392,15 @@ class PDFNodeStreamFsRangeReader extends BaseRangeReader {
constructor(stream, start, end) {
super(stream);
let path = decodeURI(this._url.path);
// Remove the extra slash to get right path from url like `file:///C:/`
if (fileUriRegex.test(this._url.href)) {
path = path.replace(/^\//, '');
}
this._setReadableStream(
fs.createReadStream(decodeURI(this._url.path), { start, end: end - 1, }));
fs.createReadStream(path, { start, end: end - 1, }));
}
}