summaryrefslogtreecommitdiff
path: root/src/node_file.h
blob: 878d02c8ba4989d9c729ef20d7f65a982dbafb52 (plain)
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
#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 FSReqWrap : public ReqWrap<uv_fs_t> {
 public:
  FSReqWrap(Environment* env, Local<Object> req)
      : ReqWrap(env, req, AsyncWrap::PROVIDER_FSREQWRAP) {
    Wrap(object(), this);
  }

  virtual ~FSReqWrap() {
    ClearWrap(object());
  }

  void Init(const char* syscall,
            const char* data = nullptr,
            size_t len = 0,
            enum encoding encoding = UTF8);

  virtual void FillStatsArray(const uv_stat_t* stat);
  virtual void Reject(Local<Value> reject);
  virtual void Resolve(Local<Value> value);
  virtual void ResolveStat();

  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(FSReqWrap);
};

class FSReqAfterScope {
 public:
  FSReqAfterScope(FSReqWrap* wrap, uv_fs_t* req);
  ~FSReqAfterScope();

  bool Proceed();

  void Reject(uv_fs_t* req);

 private:
  FSReqWrap* 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_