Merge pull request #9323 from juncaixinchi/master
Get correct path in node_stream on windows platform( issue #9020)
This commit is contained in:
commit
237bc2ef9d
@ -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, }));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user