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 46c8c94

Browse filesBrowse files
ronkorvingjasnell
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 a04408a commit 46c8c94
Copy full SHA for 46c8c94

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
@@ -614,25 +614,21 @@ fs.readSync = function(fd, buffer, offset, length, position) {
614614
// OR
615615
// fs.write(fd, string[, position[, encoding]], callback);
616616
fs.write = function(fd, buffer, offset, length, position, callback) {
617-
function strWrapper(err, written) {
617+
function wrapper(err, written) {
618618
// Retain a reference to buffer so that it can't be GC'ed too soon.
619619
callback(err, written || 0, buffer);
620620
}
621621

622-
function bufWrapper(err, written) {
623-
// retain reference to string in case it's external
624-
callback(err, written || 0, buffer);
625-
}
626-
627622
var req = new FSReqWrap();
623+
req.oncomplete = wrapper;
624+
628625
if (buffer instanceof Buffer) {
629626
// if no position is passed then assume null
630627
if (typeof position === 'function') {
631628
callback = position;
632629
position = null;
633630
}
634631
callback = maybeCallback(callback);
635-
req.oncomplete = strWrapper;
636632
return binding.writeBuffer(fd, buffer, offset, length, position, req);
637633
}
638634

@@ -648,7 +644,6 @@ fs.write = function(fd, buffer, offset, length, position, callback) {
648644
length = 'utf8';
649645
}
650646
callback = maybeCallback(position);
651-
req.oncomplete = bufWrapper;
652647
return binding.writeString(fd, buffer, offset, length, req);
653648
};
654649

0 commit comments

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