-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
Fix: #170 Credit: @coreyfarrell
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,8 +95,7 @@ function patch (fs) { | |
// Everything that references the open() function needs to be in here | ||
polyfills(fs) | ||
fs.gracefulify = patch | ||
fs.FileReadStream = ReadStream; // Legacy name. | ||
fs.FileWriteStream = WriteStream; // Legacy name. | ||
|
||
fs.createReadStream = createReadStream | ||
fs.createWriteStream = createWriteStream | ||
var fs$readFile = fs.readFile | ||
|
@@ -213,8 +212,48 @@ function patch (fs) { | |
WriteStream.prototype.open = WriteStream$open | ||
} | ||
|
||
fs.ReadStream = ReadStream | ||
fs.WriteStream = WriteStream | ||
Object.defineProperty(fs, 'ReadStream', { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
coreyfarrell
Collaborator
|
||
get: function () { | ||
return ReadStream | ||
}, | ||
set: function (val) { | ||
ReadStream = val | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}) | ||
Object.defineProperty(fs, 'WriteStream', { | ||
get: function () { | ||
return WriteStream | ||
}, | ||
set: function (val) { | ||
WriteStream = val | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}) | ||
|
||
// legacy names | ||
Object.defineProperty(fs, 'FileReadStream', { | ||
get: function () { | ||
return ReadStream | ||
}, | ||
set: function (val) { | ||
ReadStream = val | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}) | ||
Object.defineProperty(fs, 'FileWriteStream', { | ||
get: function () { | ||
return WriteStream | ||
}, | ||
set: function (val) { | ||
WriteStream = val | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}) | ||
|
||
function ReadStream (path, options) { | ||
if (this instanceof ReadStream) | ||
|
@@ -260,11 +299,11 @@ function patch (fs) { | |
} | ||
|
||
function createReadStream (path, options) { | ||
return new ReadStream(path, options) | ||
return new fs.ReadStream(path, options) | ||
} | ||
|
||
function createWriteStream (path, options) { | ||
return new WriteStream(path, options) | ||
return new fs.WriteStream(path, options) | ||
} | ||
|
||
var fs$open = fs.open | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH) { | ||
require('tap').plan(0, 'obviously not relevant when monkeypatching fs') | ||
process.exit(0) | ||
} | ||
|
||
const fs = require('fs') | ||
|
||
// Save originals before loading graceful-fs | ||
const names = [ | ||
'ReadStream', | ||
'WriteStream', | ||
'FileReadStream', | ||
'FileWriteStream' | ||
] | ||
const orig = {} | ||
names.forEach(name => orig[name] = fs[name]) | ||
|
||
const t = require('tap') | ||
const gfs = require('../') | ||
|
||
if (names.some(name => gfs[name] === orig[name])) { | ||
t.plan(0, 'graceful-fs was loaded before this test was run') | ||
process.exit(0) | ||
} | ||
|
||
t.plan(names.length) | ||
names.forEach(name => { | ||
t.ok(fs[name] === orig[name], `fs.${name} unchanged`) | ||
}) |
Not sure why, but this change makes
hasha.fromFile(anyPath)
cause stack overflows - had to downgrade back to 4.2.1