class SF::MemoryInputStream
- SF::MemoryInputStream
- SF::InputStream
- Reference
- Object
Overview
Implementation of input stream based on a memory chunk
This class is a specialization of InputStream
that
reads from data in memory.
It wraps a memory chunk in the common InputStream
interface
and therefore allows to use generic classes or functions
that accept such a stream, with content already loaded in memory.
In addition to the virtual functions inherited from
InputStream
, MemoryInputStream
adds a function to
specify the pointer and size of the data in memory.
SFML resource classes can usually be loaded directly from memory, so this class shouldn't be useful to you unless you create your own algorithms that operate on an InputStream.
Usage example:
def process(stream : InputStream)
end
stream = SF::MemoryInputStream.open(slice)
process(stream)
See also: InputStream
, FileInputStream
Defined in:
system/obj.crConstructors
-
.new
Default constructor
-
.open(*args, **kwargs) : self
Shorthand for
memory_input_stream = MemoryInputStream.new; memory_input_stream.open(...); memory_input_stream
Instance Method Summary
-
#dup : MemoryInputStream
Returns a shallow copy of this object.
- #finalize
-
#open(data : Slice)
Open the stream from its data
-
#read(data : Slice) : Int64
Read data from the stream
-
#seek(position : Int) : Int64
Change the current reading position
-
#size : Int64
Return the size of the stream
-
#tell : Int64
Get the current reading position in the stream
Instance methods inherited from class SF::InputStream
finalize
finalize,
read(data : Slice) : Int64
read,
seek(position : Int) : Int64
seek,
size : Int64
size,
tell : Int64
tell
Constructor methods inherited from class SF::InputStream
new
new
Constructor Detail
Shorthand for memory_input_stream = MemoryInputStream.new; memory_input_stream.open(...); memory_input_stream
Instance Method Detail
Returns a shallow copy of this object.
This allocates a new object and copies the contents of
self
into it.
Read data from the stream
After reading, the stream's reading position must be advanced by the amount of bytes read.
- data - Buffer where to copy the read data
Returns: The number of bytes actually read, or -1 on error
Change the current reading position
- position - The position to seek to, from the beginning
Returns: The position actually sought to, or -1 on error
Return the size of the stream
Returns: The total number of bytes available in the stream, or -1 on error
Get the current reading position in the stream
Returns: The current position, or -1 on error.