Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4c9abbd

Browse filesBrowse files
ronkorvingrvagg
authored andcommitted
fs: reduced duplicate code in fs.write()
PR-URL: #2947 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent 134a60c commit 4c9abbd
Copy full SHA for 4c9abbd

File tree

Expand file treeCollapse file tree

1 file changed

+3
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+3
-8
lines changed
Open diff view settings
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+3-8Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,25 +662,21 @@ fs.readSync = function(fd, buffer, offset, length, position) {
662662
// OR
663663
// fs.write(fd, string[, position[, encoding]], callback);
664664
fs.write = function(fd, buffer, offset, length, position, callback) {
665-
function strWrapper(err, written) {
665+
function wrapper(err, written) {
666666
// Retain a reference to buffer so that it can't be GC'ed too soon.
667667
callback(err, written || 0, buffer);
668668
}
669669

670-
function bufWrapper(err, written) {
671-
// retain reference to string in case it's external
672-
callback(err, written || 0, buffer);
673-
}
674-
675670
var req = new FSReqWrap();
671+
req.oncomplete = wrapper;
672+
676673
if (buffer instanceof Buffer) {
677674
// if no position is passed then assume null
678675
if (typeof position === 'function') {
679676
callback = position;
680677
position = null;
681678
}
682679
callback = maybeCallback(callback);
683-
req.oncomplete = strWrapper;
684680
return binding.writeBuffer(fd, buffer, offset, length, position, req);
685681
}
686682

@@ -696,7 +692,6 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
696692
length = 'utf8';
697693
}
698694
callback = maybeCallback(position);
699-
req.oncomplete = bufWrapper;
700695
return binding.writeString(fd, buffer, offset, length, req);
701696
};
702697

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.