Struct physfs_sys::PHYSFS_Io[][src]

#[repr(C)]
pub struct PHYSFS_Io { pub version: PHYSFS_uint32, pub opaque: *mut c_void, pub read: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io, buf: *mut c_void, len: PHYSFS_uint64) -> PHYSFS_sint64>, pub write: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io, buffer: *const c_void, len: PHYSFS_uint64) -> PHYSFS_sint64>, pub seek: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io, offset: PHYSFS_uint64) -> c_int>, pub tell: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io) -> PHYSFS_sint64>, pub length: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io) -> PHYSFS_sint64>, pub duplicate: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io) -> *mut PHYSFS_Io>, pub flush: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io) -> c_int>, pub destroy: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io)>, }
Expand description

\struct PHYSFS_Io \brief An abstract i/o interface.

\warning This is advanced, hardcore stuff. You don’t need this unless you really know what you’re doing. Most apps will not need this.

Historically, PhysicsFS provided access to the physical filesystem and archives within that filesystem. However, sometimes you need more power than this. Perhaps you need to provide an archive that is entirely contained in RAM, or you need to bridge some other file i/o API to PhysicsFS, or you need to translate the bits (perhaps you have a a standard .zip file that’s encrypted, and you need to decrypt on the fly for the unsuspecting zip archiver).

A PHYSFS_Io is the interface that Archivers use to get archive data. Historically, this has mapped to file i/o to the physical filesystem, but as of PhysicsFS 2.1, applications can provide their own i/o implementations at runtime.

This interface isn’t necessarily a good universal fit for i/o. There are a few requirements of note:

  • They only do blocking i/o (at least, for now).
  • They need to be able to duplicate. If you have a file handle from fopen(), you need to be able to create a unique clone of it (so we have two handles to the same file that can both seek/read/etc without stepping on each other).
  • They need to know the size of their entire data set.
  • They need to be able to seek and rewind on demand.

…in short, you’re probably not going to write an HTTP implementation.

Thread safety: PHYSFS_Io implementations are not guaranteed to be thread safe in themselves. Under the hood where PhysicsFS uses them, the library provides its own locks. If you plan to use them directly from separate threads, you should either use mutexes to protect them, or don’t use the same PHYSFS_Io from two threads at the same time.

\sa PHYSFS_mountIo

Fields

version: PHYSFS_uint32

\brief Binary compatibility information.

This must be set to zero at this time. Future versions of this struct will increment this field, so we know what a given implementation supports. We’ll presumably keep supporting older versions as we offer new features, though.

opaque: *mut c_void

\brief Instance data for this struct.

Each instance has a pointer associated with it that can be used to store anything it likes. This pointer is per-instance of the stream, so presumably it will change when calling duplicate(). This can be deallocated during the destroy() method.

read: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io, buf: *mut c_void, len: PHYSFS_uint64) -> PHYSFS_sint64>

\brief Read more data.

Read (len) bytes from the interface, at the current i/o position, and store them in (buffer). The current i/o position should move ahead by the number of bytes successfully read.

You don’t have to implement this; set it to NULL if not implemented. This will only be used if the file is opened for reading. If set to NULL, a default implementation that immediately reports failure will be used.

\param io The i/o instance to read from. \param buf The buffer to store data into. It must be at least (len) bytes long and can’t be NULL. \param len The number of bytes to read from the interface. \return number of bytes read from file, 0 on EOF, -1 if complete failure.

write: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io, buffer: *const c_void, len: PHYSFS_uint64) -> PHYSFS_sint64>

\brief Write more data.

Write (len) bytes from (buffer) to the interface at the current i/o position. The current i/o position should move ahead by the number of bytes successfully written.

You don’t have to implement this; set it to NULL if not implemented. This will only be used if the file is opened for writing. If set to NULL, a default implementation that immediately reports failure will be used.

You are allowed to buffer; a write can succeed here and then later fail when flushing. Note that PHYSFS_setBuffer() may be operating a level above your i/o, so you should usually not implement your own buffering routines.

\param io The i/o instance to write to. \param buffer The buffer to read data from. It must be at least (len) bytes long and can’t be NULL. \param len The number of bytes to read from (buffer). \return number of bytes written to file, -1 if complete failure.

seek: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io, offset: PHYSFS_uint64) -> c_int>

\brief Move i/o position to a given byte offset from start.

This method moves the i/o position, so the next read/write will be of the byte at (offset) offset. Seeks past the end of file should be treated as an error condition.

\param io The i/o instance to seek. \param offset The new byte offset for the i/o position. \return non-zero on success, zero on error.

tell: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io) -> PHYSFS_sint64>

\brief Report current i/o position.

Return bytes offset, or -1 if you aren’t able to determine. A failure will almost certainly be fatal to further use of this stream, so you may not leave this unimplemented.

\param io The i/o instance to query. \return The current byte offset for the i/o position, -1 if unknown.

length: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io) -> PHYSFS_sint64>

\brief Determine size of the i/o instance’s dataset.

Return number of bytes available in the file, or -1 if you aren’t able to determine. A failure will almost certainly be fatal to further use of this stream, so you may not leave this unimplemented.

\param io The i/o instance to query. \return Total size, in bytes, of the dataset.

duplicate: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io) -> *mut PHYSFS_Io>

\brief Duplicate this i/o instance.

This needs to result in a full copy of this PHYSFS_Io, that can live completely independently. The copy needs to be able to perform all its operations without altering the original, including either object being destroyed separately (so, for example: they can’t share a file handle; they each need their own).

If you can’t duplicate a handle, it’s legal to return NULL, but you almost certainly need this functionality if you want to use this to PHYSFS_Io to back an archive.

\param io The i/o instance to duplicate. \return A new value for a stream’s (opaque) field, or NULL on error.

flush: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io) -> c_int>

\brief Flush resources to media, or wherever.

This is the chance to report failure for writes that had claimed success earlier, but still had a chance to actually fail. This method can be NULL if flushing isn’t necessary.

This function may be called before destroy(), as it can report failure and destroy() can not. It may be called at other times, too.

\param io The i/o instance to flush. \return Zero on error, non-zero on success.

destroy: Option<unsafe extern "C" fn(io: *mut PHYSFS_Io)>

\brief Cleanup and deallocate i/o instance.

Free associated resources, including (opaque) if applicable.

This function must always succeed: as such, it returns void. The system may call your flush() method before this. You may report failure there if necessary. This method may still be called if flush() fails, in which case you’ll have to abandon unflushed data and other failing conditions and clean up.

Once this method is called for a given instance, the system will assume it is unsafe to touch that instance again and will discard any references to it.

\param s The i/o instance to destroy.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.