Web API Reference | MapGuide Open Source

- Overview
- Modules
- Classes

# MgByteSink Class Reference
[MgByteSink]

MgByteSink is a used to write the content of a MgByteReader object to a file. MgByteSink is, like MgByteReader, inherently read-only. More...

Inherits MgGuardDisposable.

List of all members.

## Public Member Functions
| MgByteSink (MgByteReader *reader)
| Construct a MgByteSink object from a source byte reader.
void | ToFile (CREFSTRING filename)
| Writes the content of the byte reader to a file. If the full contents of the reader cannot be written to the file then the file is deleted and an MgException is raised.

## Detailed Description

MgByteSink is a used to write the content of a MgByteReader object to a file. MgByteSink is, like MgByteReader, inherently read-only.

Remarks:
  Here are a few scenarios to illustrate how MgByteSink, MgByteSource and MgByteReader interact:
  Loading the content of a file and creating a byte reader to be passed to a service API:
  1. Create a MgByteSource passing the file name to its constructor
  2. Get a MgByteReader from this byte source using MgByteSource::GetReader() and pass the obtained reference to the service API
  Receiving a byte reader from a service API and saving the result into a file:
  1. Create a MgByteSink object passing the MgByteReader reference to its constructor
  2. Call the method ToFile() on the MgByteSink object.
  Saving the content of a memory buffer (or of a string) into a file:
  1. Create a MgByteSource object passing to its constructor the buffer and the number of bytes in this buffer
  2. Get a MgByteReader from this byte source using MgByteSource::GetReader()
  3. Create a MgByteSink object passing the MgByteReader reference to its constructor
  4. Call the method ToFile() on the MgByteSink object.
  Copying a file to another file:
  1. Create a MgByteSource object passing to its constructor the pathname of the source file.
  2. Get a MgByteReader from this byte source using MgByteSource::GetReader().
  3. Create a MgByteSink object passing the MgByteReader reference to its constructor.
  4. Call the method ToFile() on the MgByteSink object.

Comments or suggestions? Send us feedback.