gi-gio-2.0.35: Gio bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | Safe-Inferred
Language | Haskell2010

GI.Gio.Objects.BufferedInputStream

Contents

- Exported types
- Methods
  - fill
  - fillAsync
  - fillFinish
  - getAvailable
  - getBufferSize
  - new
  - newSized
  - peek
  - peekBuffer
  - readByte
  - setBufferSize
- Properties
  - bufferSize

Description

Buffered input stream implements `FilterInputStream` and provides for buffered reads.

By default, `GBufferedInputStream`'s buffer size is set at 4 kilobytes.

To create a buffered input stream, use `bufferedInputStreamNew`, or `bufferedInputStreamNewSized` to specify the buffer's size at construction.

To get the size of a buffer within a buffered input stream, use `bufferedInputStreamGetBufferSize`. To change the size of a buffered input stream's buffer, use `bufferedInputStreamSetBufferSize`. Note that the buffer's size cannot be reduced below the size of the data within the buffer.

Synopsis

- newtype BufferedInputStream = BufferedInputStream (ManagedPtr BufferedInputStream)
- class (GObject o, IsDescendantOf BufferedInputStream o) => IsBufferedInputStream o
- toBufferedInputStream :: (MonadIO m, IsBufferedInputStream o) => o -> m BufferedInputStream
- bufferedInputStreamFill :: (HasCallStack, MonadIO m, IsBufferedInputStream a, IsCancellable b) => a -> Int64 -> Maybe b -> m Int64
- bufferedInputStreamFillAsync :: (HasCallStack, MonadIO m, IsBufferedInputStream a, IsCancellable b) => a -> Int64 -> Int32 -> Maybe b -> Maybe AsyncReadyCallback -> m ()
- bufferedInputStreamFillFinish :: (HasCallStack, MonadIO m, IsBufferedInputStream a, IsAsyncResult b) => a -> b -> m Int64
- bufferedInputStreamGetAvailable :: (HasCallStack, MonadIO m, IsBufferedInputStream a) => a -> m CSize
- bufferedInputStreamGetBufferSize :: (HasCallStack, MonadIO m, IsBufferedInputStream a) => a -> m CSize
- bufferedInputStreamNew :: (HasCallStack, MonadIO m, IsInputStream a) => a -> m BufferedInputStream
- bufferedInputStreamNewSized :: (HasCallStack, MonadIO m, IsInputStream a) => a -> CSize -> m BufferedInputStream
- bufferedInputStreamPeek :: (HasCallStack, MonadIO m, IsBufferedInputStream a) => a -> ByteString -> CSize -> m CSize
- bufferedInputStreamPeekBuffer :: (HasCallStack, MonadIO m, IsBufferedInputStream a) => a -> m ByteString
- bufferedInputStreamReadByte :: (HasCallStack, MonadIO m, IsBufferedInputStream a, IsCancellable b) => a -> Maybe b -> m Int32
- bufferedInputStreamSetBufferSize :: (HasCallStack, MonadIO m, IsBufferedInputStream a) => a -> CSize -> m ()
- constructBufferedInputStreamBufferSize :: (IsBufferedInputStream o, MonadIO m) => Word32 -> m (GValueConstruct o)
- getBufferedInputStreamBufferSize :: (MonadIO m, IsBufferedInputStream o) => o -> m Word32
- setBufferedInputStreamBufferSize :: (MonadIO m, IsBufferedInputStream o) => o -> Word32 -> m ()

# Exported types

newtype BufferedInputStream Source #

Memory-managed wrapper type.

Constructors

BufferedInputStream (ManagedPtr BufferedInputStream) |

#### Instances

Instances details

Eq BufferedInputStream Source # |
Instance details Defined in GI.Gio.Objects.BufferedInputStream Methods (==) :: BufferedInputStream -> BufferedInputStream -> Bool Source # (/=) :: BufferedInputStream -> BufferedInputStream -> Bool Source #
GObject BufferedInputStream Source # |
Instance details Defined in GI.Gio.Objects.BufferedInputStream
ManagedPtrNewtype BufferedInputStream Source # |
Instance details Defined in GI.Gio.Objects.BufferedInputStream Methods toManagedPtr :: BufferedInputStream -> ManagedPtr BufferedInputStream Source #
TypedObject BufferedInputStream Source # |
Instance details Defined in GI.Gio.Objects.BufferedInputStream Methods glibType :: IO GType Source #
HasParentTypes BufferedInputStream Source # |
Instance details Defined in GI.Gio.Objects.BufferedInputStream
IsGValue (Maybe BufferedInputStream) Source # | Convert `BufferedInputStream` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.Gio.Objects.BufferedInputStream Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe BufferedInputStream -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe BufferedInputStream) Source #
type ParentTypes BufferedInputStream Source # |
Instance details Defined in GI.Gio.Objects.BufferedInputStream type ParentTypes BufferedInputStream = '[FilterInputStream, InputStream, Object, Seekable]

class (GObject o, IsDescendantOf BufferedInputStream o) => IsBufferedInputStream o Source #

Type class for types which can be safely cast to `BufferedInputStream`, for instance with `toBufferedInputStream`.

#### Instances

Instances details

(GObject o, IsDescendantOf BufferedInputStream o) => IsBufferedInputStream o Source # |
Instance details Defined in GI.Gio.Objects.BufferedInputStream

toBufferedInputStream :: (MonadIO m, IsBufferedInputStream o) => o -> m BufferedInputStream Source #

Cast to `BufferedInputStream`, for types for which this is known to be safe. For general casts, use `castTo`.

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

bindProperty, bindPropertyFull, canSeek, canTruncate, clearPending, close, closeAsync, closeFinish, fill, fillAsync, fillFinish, forceFloating, freezeNotify, getv, hasPending, isClosed, isFloating, notify, notifyByPspec, peek, peekBuffer, read, readAll, readAllAsync, readAllFinish, readAsync, readByte, readBytes, readBytesAsync, readBytesFinish, readFinish, ref, refSink, runDispose, seek, skip, skipAsync, skipFinish, stealData, stealQdata, tell, thawNotify, truncate, unref, watchClosure.

#### Getters

getAvailable, getBaseStream, getBufferSize, getCloseBaseStream, getData, getProperty, getQdata.

#### Setters

setBufferSize, setCloseBaseStream, setData, setDataFull, setPending, setProperty.

## fill

bufferedInputStreamFill Source #

Arguments

:: (HasCallStack, MonadIO m, IsBufferedInputStream a, IsCancellable b) |
=> a | `stream`: a `BufferedInputStream`
-> Int64 | `count`: the number of bytes that will be read from the stream
-> Maybe b | `cancellable`: optional `Cancellable` object, `NULL` to ignore
-> m Int64 | Returns: the number of bytes read into `stream`'s buffer, up to `count`, or `-1` on error. (Can throw `GError`)

Tries to read `count` bytes from the stream into the buffer. Will block during this read.

If `count` is zero, returns zero and does nothing. A value of `count` larger than `G_MAXSSIZE` will cause a [error`gio`.IOErrorEnum.INVALID_ARGUMENT] error.

On success, the number of bytes read into the buffer is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. near the end of a file. Zero is returned on end of file (or if `count` is zero), but never otherwise.

If `count` is -1 then the attempted read size is equal to the number of bytes that are required to fill the buffer.

If `cancellable` is not `NULL`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error [error`gio`.IOErrorEnum.CANCELLED] will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

On error `-1` is returned and `error` is set accordingly.

For the asynchronous, non-blocking, version of this function, see `bufferedInputStreamFillAsync`.

## fillAsync

bufferedInputStreamFillAsync Source #

Arguments

:: (HasCallStack, MonadIO m, IsBufferedInputStream a, IsCancellable b) |
=> a | `stream`: a `BufferedInputStream`
-> Int64 | `count`: the number of bytes that will be read from the stream
-> Int32 | `ioPriority`: the I/O priority of the request
-> Maybe b | `cancellable`: optional `Cancellable` object
-> Maybe AsyncReadyCallback | `callback`: a [callback`gio`.AsyncReadyCallback]
-> m () |

Reads data into `stream`'s buffer asynchronously, up to `count` size. `ioPriority` can be used to prioritize reads. For the synchronous version of this function, see `bufferedInputStreamFill`.

If `count` is `-1` then the attempted read size is equal to the number of bytes that are required to fill the buffer.

## fillFinish

bufferedInputStreamFillFinish Source #

Arguments

:: (HasCallStack, MonadIO m, IsBufferedInputStream a, IsAsyncResult b) |
=> a | `stream`: a `BufferedInputStream`
-> b | `result`: a `AsyncResult`
-> m Int64 | Returns: a `gssize` of the read stream, or `-1` on an error. (Can throw `GError`)

Finishes an asynchronous read.

## getAvailable

bufferedInputStreamGetAvailable Source #

Arguments

:: (HasCallStack, MonadIO m, IsBufferedInputStream a) |
=> a | `stream`: `BufferedInputStream`
-> m CSize | Returns: size of the available stream.

Gets the size of the available data within the stream.

## getBufferSize

bufferedInputStreamGetBufferSize Source #

Arguments

:: (HasCallStack, MonadIO m, IsBufferedInputStream a) |
=> a | `stream`: a `BufferedInputStream`
-> m CSize | Returns: the current buffer size.

Gets the size of the input buffer.

## new

bufferedInputStreamNew Source #

Arguments

:: (HasCallStack, MonadIO m, IsInputStream a) |
=> a | `baseStream`: a `InputStream`
-> m BufferedInputStream | Returns: a `InputStream` for the given `baseStream`.

Creates a new `InputStream` from the given `baseStream`, with a buffer set to the default size (4 kilobytes).

## newSized

bufferedInputStreamNewSized Source #

Arguments

:: (HasCallStack, MonadIO m, IsInputStream a) |
=> a | `baseStream`: a `InputStream`
-> CSize | `size`: a `gsize`
-> m BufferedInputStream | Returns: a `InputStream`.

Creates a new `BufferedInputStream` from the given `baseStream`, with a buffer set to `size`.

## peek

bufferedInputStreamPeek Source #

Arguments

:: (HasCallStack, MonadIO m, IsBufferedInputStream a) |
=> a | `stream`: a `BufferedInputStream`
-> ByteString | `buffer`: a pointer to an allocated chunk of memory
-> CSize | `offset`: a `gsize`
-> m CSize | Returns: a `gsize` of the number of bytes peeked, or `-1` on error.

Peeks in the buffer, copying data of size `count` into `buffer`, offset `offset` bytes.

## peekBuffer

bufferedInputStreamPeekBuffer Source #

Arguments

:: (HasCallStack, MonadIO m, IsBufferedInputStream a) |
=> a | `stream`: a `BufferedInputStream`
-> m ByteString | Returns: read-only buffer

Returns the buffer with the currently available bytes. The returned buffer must not be modified and will become invalid when reading from the stream or filling the buffer.

## readByte

bufferedInputStreamReadByte Source #

Arguments

:: (HasCallStack, MonadIO m, IsBufferedInputStream a, IsCancellable b) |
=> a | `stream`: a `BufferedInputStream`
-> Maybe b | `cancellable`: optional `Cancellable` object, `NULL` to ignore
-> m Int32 | Returns: the byte read from the `stream`, or `-1` on end of stream or error. (Can throw `GError`)

Tries to read a single byte from the stream or the buffer. Will block during this read.

On success, the byte read from the stream is returned. On end of stream `-1` is returned but it's not an exceptional error and `error` is not set.

If `cancellable` is not `NULL`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error [error`gio`.IOErrorEnum.CANCELLED] will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

On error `-1` is returned and `error` is set accordingly.

## setBufferSize

bufferedInputStreamSetBufferSize Source #

Arguments

:: (HasCallStack, MonadIO m, IsBufferedInputStream a) |
=> a | `stream`: a `BufferedInputStream`
-> CSize | `size`: a `gsize`
-> m () |

Sets the size of the internal buffer of `stream` to `size`, or to the size of the contents of the buffer. The buffer can never be resized smaller than its current contents.

# Properties

## bufferSize

The size of the backend buffer, in bytes.

constructBufferedInputStreamBufferSize :: (IsBufferedInputStream o, MonadIO m) => Word32 -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`buffer-size`” property. This is rarely needed directly, but it is used by `new`.

getBufferedInputStreamBufferSize :: (MonadIO m, IsBufferedInputStream o) => o -> m Word32 Source #

Get the value of the “`buffer-size`” property. When overloading is enabled, this is equivalent to

    get bufferedInputStream #bufferSize

setBufferedInputStreamBufferSize :: (MonadIO m, IsBufferedInputStream o) => o -> Word32 -> m () Source #

Set the value of the “`buffer-size`” property. When overloading is enabled, this is equivalent to

    set bufferedInputStream [ #bufferSize := value ]