forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnode_file.h
More file actions
121 lines (91 loc) · 2.72 KB
/
node_file.h
File metadata and controls
121 lines (91 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef SRC_NODE_FILE_H_
#define SRC_NODE_FILE_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "node.h"
#include "req_wrap-inl.h"
namespace node {
using v8::Context;
using v8::HandleScope;
using v8::Local;
using v8::Object;
using v8::Undefined;
using v8::Value;
namespace fs {
class FSReqBase : public ReqWrap<uv_fs_t> {
public:
FSReqBase(Environment* env, Local<Object> req, AsyncWrap::ProviderType type)
: ReqWrap(env, req, type) {
Wrap(object(), this);
}
virtual ~FSReqBase() {
ClearWrap(object());
}
void Init(const char* syscall,
const char* data = nullptr,
size_t len = 0,
enum encoding encoding = UTF8) {
syscall_ = syscall;
encoding_ = encoding;
if (data != nullptr) {
CHECK_EQ(data_, nullptr);
buffer_.AllocateSufficientStorage(len + 1);
buffer_.SetLengthAndZeroTerminate(len);
memcpy(*buffer_, data, len);
data_ = *buffer_;
}
}
virtual void FillStatsArray(const uv_stat_t* stat) = 0;
virtual void Reject(Local<Value> reject) = 0;
virtual void Resolve(Local<Value> value) = 0;
virtual void ResolveStat() = 0;
const char* syscall() const { return syscall_; }
const char* data() const { return data_; }
enum encoding encoding() const { return encoding_; }
size_t self_size() const override { return sizeof(*this); }
private:
enum encoding encoding_ = UTF8;
const char* syscall_;
const char* data_ = nullptr;
MaybeStackBuffer<char> buffer_;
DISALLOW_COPY_AND_ASSIGN(FSReqBase);
};
class FSReqWrap : public FSReqBase {
public:
FSReqWrap(Environment* env, Local<Object> req)
: FSReqBase(env, req, AsyncWrap::PROVIDER_FSREQWRAP) { }
void FillStatsArray(const uv_stat_t* stat) override;
void Reject(Local<Value> reject) override;
void Resolve(Local<Value> value) override;
void ResolveStat() override;
private:
DISALLOW_COPY_AND_ASSIGN(FSReqWrap);
};
class FSReqPromise : public FSReqBase {
public:
FSReqPromise(Environment* env, Local<Object> req);
~FSReqPromise() override;
void FillStatsArray(const uv_stat_t* stat) override;
void Reject(Local<Value> reject) override;
void Resolve(Local<Value> value) override;
void ResolveStat() override;
private:
bool finished_ = false;
double statFields_[14] {};
DISALLOW_COPY_AND_ASSIGN(FSReqPromise);
};
class FSReqAfterScope {
public:
FSReqAfterScope(FSReqBase* wrap, uv_fs_t* req);
~FSReqAfterScope();
bool Proceed();
void Reject(uv_fs_t* req);
private:
FSReqBase* wrap_ = nullptr;
uv_fs_t* req_ = nullptr;
HandleScope handle_scope_;
Context::Scope context_scope_;
};
} // namespace fs
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_NODE_FILE_H_