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';
|
} from '../shared/util';
|
||||||
import { validateRangeRequestCapabilities } from './network_utils';
|
import { validateRangeRequestCapabilities } from './network_utils';
|
||||||
|
|
||||||
|
const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
|
||||||
|
|
||||||
class PDFNodeStream {
|
class PDFNodeStream {
|
||||||
constructor(source) {
|
constructor(source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
@ -362,8 +364,14 @@ class PDFNodeStreamRangeReader extends BaseRangeReader {
|
|||||||
class PDFNodeStreamFsFullReader extends BaseFullReader {
|
class PDFNodeStreamFsFullReader extends BaseFullReader {
|
||||||
constructor(stream) {
|
constructor(stream) {
|
||||||
super(stream);
|
super(stream);
|
||||||
|
|
||||||
let path = decodeURI(this._url.path);
|
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) => {
|
fs.lstat(path, (error, stat) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this._errored = true;
|
this._errored = true;
|
||||||
@ -384,8 +392,15 @@ class PDFNodeStreamFsRangeReader extends BaseRangeReader {
|
|||||||
constructor(stream, start, end) {
|
constructor(stream, start, end) {
|
||||||
super(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(/^\//, '');
|
||||||
|
}
|
||||||
|
|
||||||
this._setReadableStream(
|
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