Asio Extensions
Additional functionality built on top of (Boost.)Asio
asioext::write_file()

Functions

template<class ConstBufferSequence >
void asioext::write_file (const char *filename, const ConstBufferSequence &buffers)
 
template<class ConstBufferSequence >
void asioext::write_file (const char *filename, const ConstBufferSequence &buffers, error_code &ec) noexcept
 
template<class ConstBufferSequence >
void asioext::write_file (const wchar_t *filename, const ConstBufferSequence &buffers)
 
template<class ConstBufferSequence >
void asioext::write_file (const wchar_t *filename, const ConstBufferSequence &buffers, error_code &ec) noexcept
 
template<class ConstBufferSequence >
void asioext::write_file (const boost::filesystem::path &filename, const ConstBufferSequence &buffers)
 
template<class ConstBufferSequence >
void asioext::write_file (const boost::filesystem::path &filename, const ConstBufferSequence &buffers, error_code &ec) noexcept
 

Detailed Description

Writes a sequence of buffers to a file.

Example
const std::string d1("Hallo Welt!\n");
const char d2[] = "Hello World!\n";
const std::vector<char> d3{'H', 'i', '\n'};
asio::buffer(d1),
asio::buffer(d2, std::size(d2) - 1), // term. NUL
asio::buffer(d3)
};
asioext::write_file("test.txt", bufs1);
// test.txt now contains three lines: Hallo Welt!, Hello World, Hi

Function Documentation

◆ write_file() [1/6]

template<class ConstBufferSequence >
void asioext::write_file ( const char *  filename,
const ConstBufferSequence buffers 
)

Write a sequence of buffers to a file.

This function writes buffers into filename. If the file already exists, it is overwritten. After a successful call to this function, the file shall only contain the contents of the given buffers.

Parameters
filenameThe path of the file into which the buffer content shall be written.
buffersThe sequence of buffers to write to the file.
Exceptions
asio::system_errorThrown on failure.

◆ write_file() [2/6]

template<class ConstBufferSequence >
void asioext::write_file ( const char *  filename,
const ConstBufferSequence buffers,
error_code ec 
)
noexcept

Write a sequence of buffers to a file.

This function writes buffers into filename. If the file already exists, it is overwritten. After a successful call to this function, the file shall only contain the contents of the given buffers.

Parameters
filenameThe path of the file into which the buffer content shall be written.
buffersThe sequence of buffers to write to the file.
ecSet to indicate what error occurred. If no error occurred, the object is reset.

◆ write_file() [3/6]

template<class ConstBufferSequence >
void asioext::write_file ( const wchar_t *  filename,
const ConstBufferSequence buffers 
)

Write a sequence of buffers to a file.

This function writes buffers into filename. If the file already exists, it is overwritten. After a successful call to this function, the file shall only contain the contents of the given buffers.

Parameters
filenameThe path of the file into which the buffer content shall be written.
buffersThe sequence of buffers to write to the file.
Exceptions
asio::system_errorThrown on failure.
Note
Only available on Windows.

◆ write_file() [4/6]

template<class ConstBufferSequence >
void asioext::write_file ( const wchar_t *  filename,
const ConstBufferSequence buffers,
error_code ec 
)
noexcept

Write a sequence of buffers to a file.

This function writes buffers into filename. If the file already exists, it is overwritten. After a successful call to this function, the file shall only contain the contents of the given buffers.

Parameters
filenameThe path of the file into which the buffer content shall be written.
buffersThe sequence of buffers to write to the file.
ecSet to indicate what error occurred. If no error occurred, the object is reset.
Note
Only available on Windows.

◆ write_file() [5/6]

template<class ConstBufferSequence >
void asioext::write_file ( const boost::filesystem::path &  filename,
const ConstBufferSequence buffers 
)

Write a sequence of buffers to a file.

This function writes buffers into filename. If the file already exists, it is overwritten. After a successful call to this function, the file shall only contain the contents of the given buffers.

Parameters
filenameThe path of the file into which the buffer content shall be written.
buffersThe sequence of buffers to write to the file.
Exceptions
asio::system_errorThrown on failure.
Note
Only available if using Boost.Filesystem (i.e. if ASIOEXT_HAS_BOOST_FILESYSTEM is defined)

◆ write_file() [6/6]

template<class ConstBufferSequence >
void asioext::write_file ( const boost::filesystem::path &  filename,
const ConstBufferSequence buffers,
error_code ec 
)
noexcept

Write a sequence of buffers to a file.

This function writes buffers into filename. If the file already exists, it is overwritten. After a successful call to this function, the file shall only contain the contents of the given buffers.

Parameters
filenameThe path of the file into which the buffer content shall be written.
buffersThe sequence of buffers to write to the file.
ecSet to indicate what error occurred. If no error occurred, the object is reset.
Note
Only available if using Boost.Filesystem (i.e. if ASIOEXT_HAS_BOOST_FILESYSTEM is defined)