@@ -1320,11 +1320,15 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
1320
1320
static void WriteBuffers (const FunctionCallbackInfo<Value>& args) {
1321
1321
Environment* env = Environment::GetCurrent (args);
1322
1322
1323
+ const int argc = args.Length ();
1324
+ CHECK_GE (argc, 3 );
1325
+
1323
1326
CHECK (args[0 ]->IsInt32 ());
1324
- CHECK ( args[1 ]-> IsArray () );
1327
+ const int fd = args[0 ]. As <Int32>()-> Value ( );
1325
1328
1326
- int fd = args[0 ]->Int32Value ( );
1329
+ CHECK ( args[1 ]->IsArray () );
1327
1330
Local<Array> chunks = args[1 ].As <Array>();
1331
+
1328
1332
int64_t pos = GET_OFFSET (args[2 ]);
1329
1333
1330
1334
MaybeStackBuffer<uv_buf_t > iovs (chunks->Length ());
@@ -1336,14 +1340,16 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
1336
1340
}
1337
1341
1338
1342
FSReqBase* req_wrap = GetReqWrap (env, args[3 ]);
1339
- if (req_wrap != nullptr ) {
1343
+ if (req_wrap != nullptr ) { // writeBuffers(fd, chunks, pos, req)
1340
1344
AsyncCall (env, req_wrap, args, " write" , UTF8, AfterInteger,
1341
1345
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);
1343
1352
}
1344
-
1345
- SYNC_CALL (write, nullptr , fd, *iovs, iovs.length (), pos)
1346
- args.GetReturnValue ().Set (SYNC_RESULT);
1347
1353
}
1348
1354
1349
1355
0 commit comments