@@ -1320,11 +1320,15 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
13201320static void WriteBuffers (const FunctionCallbackInfo<Value>& args) {
13211321 Environment* env = Environment::GetCurrent (args);
13221322
1323+ const int argc = args.Length ();
1324+ CHECK_GE (argc, 3 );
1325+
13231326 CHECK (args[0 ]->IsInt32 ());
1324- CHECK ( args[1 ]-> IsArray () );
1327+ const int fd = args[0 ]. As <Int32>()-> Value ( );
13251328
1326- int fd = args[0 ]->Int32Value ( );
1329+ CHECK ( args[1 ]->IsArray () );
13271330 Local<Array> chunks = args[1 ].As <Array>();
1331+
13281332 int64_t pos = GET_OFFSET (args[2 ]);
13291333
13301334 MaybeStackBuffer<uv_buf_t > iovs (chunks->Length ());
@@ -1336,14 +1340,16 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
13361340 }
13371341
13381342 FSReqBase* req_wrap = GetReqWrap (env, args[3 ]);
1339- if (req_wrap != nullptr ) {
1343+ if (req_wrap != nullptr ) { // writeBuffers(fd, chunks, pos, req)
13401344 AsyncCall (env, req_wrap, args, " write" , UTF8, AfterInteger,
13411345 uv_fs_write, fd, *iovs, iovs.length (), pos);
1342- return ;
1346+ } else { // writeBuffers(fd, chunks, pos, undefined, ctx)
1347+ CHECK_EQ (argc, 5 );
1348+ fs_req_wrap req_wrap;
1349+ int bytesWritten = SyncCall (env, args[4 ], &req_wrap, " write" ,
1350+ uv_fs_write, fd, *iovs, iovs.length (), pos);
1351+ args.GetReturnValue ().Set (bytesWritten);
13431352 }
1344-
1345- SYNC_CALL (write, nullptr , fd, *iovs, iovs.length (), pos)
1346- args.GetReturnValue ().Set (SYNC_RESULT);
13471353}
13481354
13491355
0 commit comments