Get correct path in node_stream on windows platform

This commit is contained in:
juncaixinchi 2018-01-13 21:13:24 +08:00
parent ba0a3aebd0
commit 8e278d9a45

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, }));
}
}