Class: UV::File

Inherits:
Object
  • Object
show all
Includes:
Assertions, Listener, Resource
Defined in:
lib/uv/file.rb,
lib/uv/file/stat.rb

Defined Under Namespace

Classes: Stat

Instance Method Summary collapse

Methods included from Assertions

#assert_arity, #assert_block, #assert_boolean, #assert_signal, #assert_type

Methods included from Resource

#check_result, #check_result!, #to_ptr

Methods included from Listener

define_callback, undefine_callbacks

Constructor Details

#initialize(loop, fd) ⇒ File

Returns a new instance of File.



5
6
7
8
# File 'lib/uv/file.rb', line 5

def initialize(loop, fd)
  @loop = loop
  @fd = Integer(fd)
end

Instance Method Details

#chmod(mode, &block) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/uv/file.rb', line 109

def chmod(mode, &block)
  assert_block(block)
  assert_arity(1, block)
  assert_type(Integer, mode, "mode must be an Integer")

  @chmod_block = block

  check_result! UV.fs_fchmod(loop.to_ptr, UV.create_request(:uv_fs), @fd, mode, callback(:on_chmod))

  self
end

#chown(uid, gid, &block) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/uv/file.rb', line 121

def chown(uid, gid, &block)
  assert_block(block)
  assert_arity(1, block)
  assert_type(Integer, uid, "uid must be an Integer")
  assert_type(Integer, gid, "gid must be an Integer")

  @chown_block = block

  check_result! UV.fs_fchown(loop.to_ptr, UV.create_request(:uv_fs), @fd, uid, gid, callback(:on_chown))

  self
end

#close(&block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/uv/file.rb', line 10

def close(&block)
  assert_block(block)
  assert_arity(1, block)

  @close_block = block

  check_result! UV.fs_close(loop.to_ptr, UV.create_request(:uv_fs), @fd, callback(:on_close))

  self
end

#datasync(&block) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/uv/file.rb', line 73

def datasync(&block)
  assert_block(block)
  assert_arity(1, block)

  @datasync_block = block

  check_result! UV.fs_fdatasync(loop.to_ptr, UV.create_request(:uv_fs), @fd, callback(:on_datasync))

  self
end

#read(length, offset = 0, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/uv/file.rb', line 21

def read(length, offset = 0, &block)
  assert_block(block)
  assert_arity(2, block)
  assert_type(Integer, length, "length must be an Integer")
  assert_type(Integer, offset, "offset must be an Integer")

  @read_block         = block
  @read_buffer_length = length
  @read_buffer        = FFI::MemoryPointer.new(@read_buffer_length)

  check_result! UV.fs_read(loop.to_ptr, UV.create_request(:uv_fs), @fd, @read_buffer, @read_buffer_length, offset, callback(:on_read))

  self
end

#stat(&block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/uv/file.rb', line 51

def stat(&block)
  assert_block(block)
  assert_arity(2, block)

  @stat_block = block

  check_result! UV.fs_fstat(loop.to_ptr, UV.create_request(:uv_fs), @fd, callback(:on_stat))

  self
end

#sync(&block) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/uv/file.rb', line 62

def sync(&block)
  assert_block(block)
  assert_arity(1, block)

  @sync_block = block

  check_result! UV.fs_fsync(loop.to_ptr, UV.create_request(:uv_fs), @fd, callback(:on_sync))

  self
end

#truncate(offset, &block) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/uv/file.rb', line 84

def truncate(offset, &block)
  assert_block(block)
  assert_arity(1, block)
  assert_type(Integer, offset, "offset must be an Integer")

  @truncate_block = block

  check_result! UV.fs_ftruncate(loop.to_ptr, UV.create_request(:uv_fs), @fd, offset, callback(:on_truncate))

  self
end

#utime(atime, mtime, &block) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/uv/file.rb', line 96

def utime(atime, mtime, &block)
  assert_block(block)
  assert_arity(1, block)
  assert_type(Integer, atime, "atime must be an Integer")
  assert_type(Integer, mtime, "mtime must be an Integer")

  @utime_block = block

  check_result! UV.fs_futime(loop.to_ptr, UV.create_request(:uv_fs), @fd, atime, mtime, callback(:on_utime))

  self
end

#write(data, offset = 0, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/uv/file.rb', line 36

def write(data, offset = 0, &block)
  assert_block(block)
  assert_arity(1, block)
  assert_type(String, data, "data must be a String")
  assert_type(Integer, offset, "offset must be an Integer")

  @write_block = block
  @write_buffer_length = data.respond_to?(:bytesize) ? data.bytesize : data.size
  @write_buffer = FFI::MemoryPointer.from_string(data)

  check_result! UV.fs_write(loop.to_ptr, UV.create_request(:uv_fs), @fd, @write_buffer, @write_buffer_length, offset, callback(:on_write))

  self
end