Device

Implements a means of reading and writing a file device. Conduits are the primary means of accessing external data, and this one is used as a superclass for the console, for files, sockets etc.

Members

Aliases

error
alias error = Conduit.error

expose superclass definition also

Functions

bufferSize
size_t bufferSize()

Return a preferred size for buffering conduit I/O.

detach
void detach()

Release the underlying file. Note that an exception is not thrown on error, as doing so can induce some spaggetti into error handling. Instead, we need to change this to return a bool instead, so the caller can decide what to do.

detach
void detach()

Release the underlying file.

dispose
void dispose()
error
void error()

Throw an IOException noting the last error.

read
size_t read(void[] dst)

Read a chunk of bytes from the file into the provided array. Returns the number of bytes read, or Eof where there is no further data.

read
size_t read(void[] dst)

Read a chunk of bytes from the file into the provided array. Returns the number of bytes read, or Eof where there is no further data.

reopen
void reopen(Handle handle)

Allow adjustment of standard IO handles.

reopen
void reopen(Handle handle)

Allow adjustment of standard IO handles.

toString
immutable(char)[] toString()

Return the name of this device.

wait
size_t wait(scheduler.Type type, uint bytes, uint timeout)
write
size_t write(const(void)[] src)

Write a chunk of bytes to the file from the provided array. Returns the number of bytes written, or Eof if the output is no longer available.

write
size_t write(const(void)[] src)

Write a chunk of bytes to the file from the provided array. Returns the number of bytes written, or Eof if the output is no longer available.

Properties

fileHandle
Handle fileHandle [@property getter]

Return the underlying OS handle of this Conduit.

fileHandle
Handle fileHandle [@property getter]

Return the underlying OS handle of this Conduit.

Structs

IO
struct IO

Windows-specific code.

Variables

handle
int handle;

Unix-specific code.

io
IO io;

Windows-specific code.

Inherited Members

From Conduit

scheduler
Fiber.Scheduler scheduler;
Undocumented in source.
~this
~this()

Clean up when collected. See method detach().

toString
string toString()

Return the name of this conduit.

bufferSize
size_t bufferSize()

Return a preferred size for buffering conduit I/O.

read
size_t read(void[] dst)

Read from conduit into a target array. The provided dst will be populated with content from the conduit.

write
size_t write(const(void)[] src)

Write to conduit from a source array. The provided src content will be written to the conduit.

detach
void detach()

Disconnect this conduit. Note that this may be invoked both explicitly by the user, and implicitly by the GC. Be sure to manage multiple detachment requests correctly: set a flag, or sentinel value as necessary.

timeout
uint timeout [@property setter]

Set the active timeout period for IO calls (in milliseconds.)

timeout
uint timeout [@property getter]

Get the active timeout period for IO calls (in milliseconds.)

isAlive
bool isAlive [@property getter]

Is the conduit alive? Default behaviour returns true.

conduit
IConduit conduit [@property getter]

Return the host. This is part of the Stream interface.

flush
IOStream flush()

Emit buffered output or reset buffered input.

close
void close()

Close this conduit.

error
void error(const(char[]) msg)

Throw an IOException, with the provided message.

input
InputStream input [@property getter]

Return the input stream.

output
OutputStream output [@property getter]

Return the output stream.

put
Conduit put(void[] src)

Emit fixed-length content from 'src' into this conduit, throwing an IOException upon Eof.

get
Conduit get(void[] dst)

Consume fixed-length content into 'dst' from this conduit, throwing an IOException upon Eof.

rewind
Conduit rewind()

Rewind to beginning of file.

copy
OutputStream copy(InputStream src, size_t max)

Transfer the content of another conduit to this one. Returns the dst OutputStream, or throws IOException on failure.

seek
long seek(long offset, Anchor anchor)

Seek on this stream. Source conduits that don't support seeking will throw an IOException.

text
char[] text(size_t max)

Load text from a stream, and return them all in an array.

load
void[] load(size_t max)

Load the bits from a stream, and return them all in an array. The dst array can be provided as an option, which will be expanded as necessary to consume the input.

load
void[] load(InputStream src, size_t max)

Load the bits from a stream, and return them all in an array. The dst array can be provided as an option, which will be expanded as necessary to consume input.

put
void put(void[] src, OutputStream output)

Emit fixed-length content from 'src' into 'output', throwing an IOException upon Eof.

get
void get(void[] dst, InputStream input)

Consume fixed-length content into 'dst' from 'input', throwing an IOException upon Eof.

transfer
size_t transfer(InputStream src, OutputStream dst, size_t max)

Low-level data transfer, where max represents the maximum number of bytes to transfer.

Meta