# Juliet\include\Core\HAL\IO\IOStream

## Source Files
- Header: `Juliet\include\Core\HAL\IO\IOStream.h`
- Source: `Juliet\src\Core\HAL\IO\IOStream.cpp`

## AI Description
The `IOStream` component in the Juliet library is designed to provide a unified interface for reading and writing data from various sources, such as files or memory buffers. It supports both file-based and memory-based operations, allowing developers to interact with different types of data sources in a consistent manner.

The `IOStream` class encapsulates the functionality required to manage the stream's state, including its status (ready, error, end of file), position within the stream, and the ability to read from or write to the stream. It also provides methods for seeking within the stream and determining its size.

The `IOFromFile` function allows developers to open a file by providing the filename and mode as parameters. The `IOFromInterface` function enables developers to use an existing interface to open any I/O stream, which can be particularly useful when integrating with external libraries or frameworks that provide custom I/O interfaces.

The `IOPrintf`, `IOWrite`, `IORead`, `IOSeek`, and `IOSize` functions are used to perform various operations on the I/O stream. These functions handle file reading and writing, as well as seeking within the stream, and return the number of bytes read or written.

The `LoadFile` function is a utility function that loads data from a file into a ByteBuffer. It uses the `IOFromFile` function to open the file and then reads its contents into a buffer. The `LoadFile` function also provides an option to close the stream after loading the data, which can be useful for freeing up resources.

The `IOClose` function is used to close the I/O stream and free any associated resources. It ensures that the stream is properly closed before it is deleted, preventing memory leaks or other issues.

## Symbols

### Namespace `Juliet`

#### Classes, Structs & Unions
- `struct IOStreamDataPayload`
- `struct IOStreamInterface`

#### Enums
- `enum class IOStreamStatus`
- `enum class IOStreamSeekPivot`

#### Functions & Methods
- `extern JULIET_API IOStream* IOFromFile(String filename, String mode)`
- `// Let you use an interface to open any io. Is used internally by IOFromFile
    extern JULIET_API IOStream* IOFromInterface(NonNullPtr<const IOStreamInterface> streamInterface, NonNullPtr<IOStreamDataPayload> payload)`
- `// Write formatted string into the stream.
    extern JULIET_API size_t IOPrintf(NonNullPtr<IOStream> stream, _Printf_format_string_ const char* format, ...)`
- `extern JULIET_API size_t IOWrite(NonNullPtr<IOStream> stream, ByteBuffer inBuffer)`
- `extern JULIET_API size_t IORead(NonNullPtr<IOStream> stream, void* ptr, size_t size)`
- `extern JULIET_API int64 IOSeek(NonNullPtr<IOStream> stream, int64 offset, IOStreamSeekPivot pivot)`
- `extern JULIET_API int64 IOSize(NonNullPtr<IOStream> stream)`
- `// TODO : Use memory arena because that Allocates
    extern JULIET_API ByteBuffer LoadFile(String filename)`
- `extern JULIET_API ByteBuffer LoadFile(NonNullPtr<IOStream> stream, bool closeStreamWhenDone)`
- `extern JULIET_API bool IOClose(NonNullPtr<IOStream> stream)`

