@@ -1965,6 +1965,52 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
1965
1965
}
1966
1966
1967
1967
1968
+ // Wrapper for readv(2).
1969
+ //
1970
+ // bytesRead = fs.readv(fd, buffers[, position], callback)
1971
+ // 0 fd integer. file descriptor
1972
+ // 1 buffers array of buffers to read
1973
+ // 2 position if integer, position to read at in the file.
1974
+ // if null, read from the current position
1975
+ static void ReadBuffers (const FunctionCallbackInfo<Value>& args) {
1976
+ Environment* env = Environment::GetCurrent (args);
1977
+
1978
+ const int argc = args.Length ();
1979
+ CHECK_GE (argc, 3 );
1980
+
1981
+ CHECK (args[0 ]->IsInt32 ());
1982
+ const int fd = args[0 ].As <Int32>()->Value ();
1983
+
1984
+ CHECK (args[1 ]->IsArray ());
1985
+ Local<Array> buffers = args[1 ].As <Array>();
1986
+
1987
+ int64_t pos = GetOffset (args[2 ]); // -1 if not a valid JS int
1988
+
1989
+ MaybeStackBuffer<uv_buf_t > iovs (buffers->Length ());
1990
+
1991
+ // Init uv buffers from ArrayBufferViews
1992
+ for (uint32_t i = 0 ; i < iovs.length (); i++) {
1993
+ Local<Value> buffer = buffers->Get (env->context (), i).ToLocalChecked ();
1994
+ CHECK (Buffer::HasInstance (buffer));
1995
+ iovs[i] = uv_buf_init (Buffer::Data (buffer), Buffer::Length (buffer));
1996
+ }
1997
+
1998
+ FSReqBase* req_wrap_async = GetReqWrap (env, args[3 ]);
1999
+ if (req_wrap_async != nullptr ) { // readBuffers(fd, buffers, pos, req)
2000
+ AsyncCall (env, req_wrap_async, args, " read" , UTF8, AfterInteger,
2001
+ uv_fs_read, fd, *iovs, iovs.length (), pos);
2002
+ } else { // readBuffers(fd, buffers, undefined, ctx)
2003
+ CHECK_EQ (argc, 5 );
2004
+ FSReqWrapSync req_wrap_sync;
2005
+ FS_SYNC_TRACE_BEGIN (read );
2006
+ int bytesRead = SyncCall (env, /* ctx */ args[4 ], &req_wrap_sync, " read" ,
2007
+ uv_fs_read, fd, *iovs, iovs.length (), pos);
2008
+ FS_SYNC_TRACE_END (read , " bytesRead" , bytesRead);
2009
+ args.GetReturnValue ().Set (bytesRead);
2010
+ }
2011
+ }
2012
+
2013
+
1968
2014
/* fs.chmod(path, mode);
1969
2015
* Wrapper for chmod(1) / EIO_CHMOD
1970
2016
*/
@@ -2228,6 +2274,7 @@ void Initialize(Local<Object> target,
2228
2274
env->SetMethod (target, " open" , Open);
2229
2275
env->SetMethod (target, " openFileHandle" , OpenFileHandle);
2230
2276
env->SetMethod (target, " read" , Read);
2277
+ env->SetMethod (target, " readBuffers" , ReadBuffers);
2231
2278
env->SetMethod (target, " fdatasync" , Fdatasync);
2232
2279
env->SetMethod (target, " fsync" , Fsync);
2233
2280
env->SetMethod (target, " rename" , Rename);
0 commit comments