top of page

File and stream I/O

 

File and stream I/O (input/output) refers to the transfer of data either to or from a storage medium. In xtd, the xtd::io namespaces contain types that enable reading and writing, both synchronously and asynchronously, on data streams and files. These namespaces also contain types that perform compression and decompression on files, and types that enable communication through pipes and serial ports.

A file is an ordered and named collection of bytes that has persistent storage. When you work with files, you work with directory paths, disk storage, and file and directory names. In contrast, a stream is a sequence of bytes that you can use to read from and write to a backing store, which can be one of several storage mediums (for example, disks or memory). Just as there are several backing stores other than disks, there are several kinds of streams other than file streams, such as network, memory, and pipe streams.

Files and directories

 

You can use the types in the xtd::io namespace to interact with files and directories. For example, you can get and set properties for files and directories, and retrieve collections of files and directories based on search criteria.

 

For path naming conventions and the ways to express a file path for Windows, macOS and Linux systems.

 

Here are some commonly used file and directory classes:

  • xtd::io::file - provides static methods for creating, copying, deleting, moving, and opening files, and helps create a FileStream object.

  • xtd::io::file_info - provides instance methods for creating, copying, deleting, moving, and opening files, and helps create a FileStream object.

  • xtd::io::directory - provides static methods for creating, moving, and enumerating through directories and subdirectories.

  • xtd::io::directory_info - provides instance methods for creating, moving, and enumerating through directories and subdirectories.

  • xtd::io::path - provides methods and properties for processing directory strings in a cross-platform manner.

 

You should always provide robust exception handling when calling filesystem methods.

Streams

 

The std classes std::ostream and std::istream and std::iostream support reading and writing bytes.

Readers and writers

 

The xtd::io namespace also provides types for reading characters from streams and writing them to streams. Typically, streams are designed for byte input and output. The reader and writer types handle the conversion of the characters to and from bytes so the stream can complete the operation. Each reader and writer class is associated with a stream.

 

Here are some commonly used reader and writer classes:

Compression

 

Not yet implemented...

See also

Readers and Writers Anchor
bottom of page