Skip to content

Commit

Permalink
Merge pull request #9323 from juncaixinchi/master
Browse files Browse the repository at this point in the history
Get correct path in node_stream on windows platform( issue #9020)
  • Loading branch information
timvandermeij authored Jan 14, 2018
2 parents a7cb560 + 8e278d9 commit 237bc2e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/display/node_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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, }));
}
}

Expand Down

0 comments on commit 237bc2e

Please sign in to comment.