class SF::FileInputStream

Overview

Implementation of input stream based on a file

This class is a specialization of InputStream that reads from a file on disk.

It wraps a file in the common InputStream interface and therefore allows to use generic classes or functions that accept such a stream, with a file on disk as the data source.

In addition to the virtual functions inherited from InputStream, FileInputStream adds a function to specify the file to open.

SFML resource classes can usually be loaded directly from a filename, 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::FileInputStream.open("some_file.dat")
process(stream)

See also: InputStream, MemoryInputStream

Included Modules

Defined in:

system/obj.cr

Constructors

Instance Method Summary

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

def self.new #

Default constructor


[View source]
def self.open(*args, **kwargs) : self #

Shorthand for file_input_stream = FileInputStream.new; file_input_stream.open(...); file_input_stream

Raises InitError on failure


[View source]

Instance Method Detail

def finalize #

Default destructor


[View source]
def open(filename : String) : Bool #

Open the stream from a file path

  • filename - Name of the file to open

Returns: True on success, false on error


[View source]
def read(data : Slice) : Int64 #

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


[View source]
def seek(position : Int) : Int64 #

Change the current reading position

  • position - The position to seek to, from the beginning

Returns: The position actually sought to, or -1 on error


[View source]
def size : Int64 #

Return the size of the stream

Returns: The total number of bytes available in the stream, or -1 on error


[View source]
def tell : Int64 #

Get the current reading position in the stream

Returns: The current position, or -1 on error.


[View source]