@@ -2205,18 +2205,20 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
22052205 iovs[i] = uv_buf_init (Buffer::Data (chunk), Buffer::Length (chunk));
22062206 }
22072207
2208- FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
2209- if (req_wrap_async != nullptr ) { // writeBuffers(fd, chunks, pos, req)
2210- FS_ASYNC_TRACE_BEGIN0 (UV_FS_WRITE, req_wrap_async)
2211- AsyncCall (env, req_wrap_async, args, " write" , UTF8, AfterInteger,
2208+ if (argc > 3 ) { // writeBuffers(fd, chunks, pos, req)
2209+ FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
2210+ FS_ASYNC_TRACE_BEGIN0 (UV_FS_WRITE, req_wrap_async)
2211+ AsyncCall (env, req_wrap_async, args, " write" , UTF8, AfterInteger,
22122212 uv_fs_write, fd, *iovs, iovs.length (), pos);
2213- } else { // writeBuffers(fd, chunks, pos, undefined, ctx)
2214- CHECK_EQ (argc, 5 );
2215- FSReqWrapSync req_wrap_sync;
2213+ } else { // writeBuffers(fd, chunks, pos)
2214+ FSReqWrapSync req_wrap_sync (" write" );
22162215 FS_SYNC_TRACE_BEGIN (write);
2217- int bytesWritten = SyncCall (env, args[ 4 ], &req_wrap_sync, " write " ,
2216+ int bytesWritten = SyncCallAndThrowOnError (env, &req_wrap_sync,
22182217 uv_fs_write, fd, *iovs, iovs.length (), pos);
22192218 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2219+ if (is_uv_error (bytesWritten)) {
2220+ return ;
2221+ }
22202222 args.GetReturnValue ().Set (bytesWritten);
22212223 }
22222224}
0 commit comments