Skip to content

Commit 9ed5946

Browse files
ngotxicilion
authored andcommitted
fs, feat: File add fd property (#256)
1 parent 18cad50 commit 9ed5946

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

fibjs/include/File.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class File : public File_base {
5050
public:
5151
// File_base
5252
virtual result_t get_name(exlib::string& retVal);
53+
virtual result_t get_fd(int32_t& retVal);
5354
virtual result_t chmod(int32_t mode, AsyncEvent* ac);
5455

5556
public:

fibjs/include/ifs/File.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class File_base : public SeekableStream_base {
2525
public:
2626
// File_base
2727
virtual result_t get_name(exlib::string& retVal) = 0;
28+
virtual result_t get_fd(int32_t& retVal) = 0;
2829
virtual result_t chmod(int32_t mode, AsyncEvent* ac) = 0;
2930

3031
public:
@@ -40,6 +41,7 @@ class File_base : public SeekableStream_base {
4041

4142
public:
4243
static void s_get_name(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
44+
static void s_get_fd(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
4345
static void s_chmod(const v8::FunctionCallbackInfo<v8::Value>& args);
4446

4547
public:
@@ -55,7 +57,8 @@ inline ClassInfo& File_base::class_info()
5557
};
5658

5759
static ClassData::ClassProperty s_property[] = {
58-
{ "name", s_get_name, block_set, false }
60+
{ "name", s_get_name, block_set, false },
61+
{ "fd", s_get_fd, block_set, false }
5962
};
6063

6164
static ClassData s_cd = {
@@ -80,6 +83,18 @@ inline void File_base::s_get_name(v8::Local<v8::String> property, const v8::Prop
8083
METHOD_RETURN();
8184
}
8285

86+
inline void File_base::s_get_fd(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
87+
{
88+
int32_t vr;
89+
90+
METHOD_INSTANCE(File_base);
91+
PROPERTY_ENTER();
92+
93+
hr = pInst->get_fd(vr);
94+
95+
METHOD_RETURN();
96+
}
97+
8398
inline void File_base::s_chmod(const v8::FunctionCallbackInfo<v8::Value>& args)
8499
{
85100
METHOD_INSTANCE(File_base);

fibjs/include/ifs/File.idl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ interface File : SeekableStream
1010
/*! @brief 查询当前文件名 */
1111
readonly String name;
1212

13+
/*! @brief 查询当前文件描述符 */
14+
readonly Integer fd;
15+
1316
/*! @brief 查询当前文件的访问权限,Windows 不支持此方法
1417
@param mode 指定设定的访问权限
1518
*/

fibjs/src/fs/File.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ result_t File::get_name(exlib::string& retVal)
252252
return 0;
253253
}
254254

255+
result_t File::get_fd(int32_t& retVal)
256+
{
257+
if (m_fd == -1)
258+
return CHECK_ERROR(CALL_E_INVALID_CALL);
259+
260+
retVal = m_fd;
261+
return 0;
262+
}
263+
255264
#ifdef _WIN32
256265

257266
result_t File::stat(obj_ptr<Stat_base>& retVal, AsyncEvent* ac)

0 commit comments

Comments
 (0)