Class: Skia::Data
Instance Attribute Summary
Attributes inherited from Base
#ptr
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#null?, release_callback, #to_ptr
Constructor Details
#initialize(ptr_or_bytes = nil) ⇒ Data
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/skia/data.rb', line 5
def initialize(ptr_or_bytes = nil)
case ptr_or_bytes
when FFI::Pointer
super(ptr_or_bytes, :sk_data_unref)
when String
ptr = Native.sk_data_new_with_copy(ptr_or_bytes, ptr_or_bytes.bytesize)
raise Error, 'Failed to create data from bytes' if ptr.nil? || ptr.null?
super(ptr, :sk_data_unref)
when nil
raise ArgumentError, 'Data requires bytes or pointer'
else
raise ArgumentError, "Invalid argument type: #{ptr_or_bytes.class}"
end
end
|
Class Method Details
.from_bytes(bytes) ⇒ Object
28
29
30
|
# File 'lib/skia/data.rb', line 28
def self.from_bytes(bytes)
new(bytes)
end
|
.from_file(path) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/skia/data.rb', line 21
def self.from_file(path)
ptr = Native.sk_data_new_from_file(path)
raise FileNotFoundError, "Failed to load file: #{path}" if ptr.nil? || ptr.null?
new(ptr)
end
|
Instance Method Details
#empty? ⇒ Boolean
36
37
38
|
# File 'lib/skia/data.rb', line 36
def empty?
size == 0
end
|
#size ⇒ Object
32
33
34
|
# File 'lib/skia/data.rb', line 32
def size
Native.sk_data_get_size(@ptr)
end
|
#to_s ⇒ Object
Also known as:
to_bytes
40
41
42
43
|
# File 'lib/skia/data.rb', line 40
def to_s
data_ptr = Native.sk_data_get_data(@ptr)
data_ptr.read_bytes(size)
end
|