Class Iso8211DocumentReader
Provides methods to read ISO 8211 formatted data and return structured objects.
public static class Iso8211DocumentReader
- Inheritance
-
Iso8211DocumentReader
- Inherited Members
Remarks
This reader uses Iso8211Reader internally for parsing. The Read methods
build a complete Iso8211Document; EnumerateRecords(ReadOnlyMemory<byte>)
returns one record at a time, so memory use doesn't grow with the size of the file.
Each field's Data is a slice of the data read rather than a copy of its own. The methods that take a byte array, a span, a file or a stream read from a private copy, so the document never shares memory with the caller. The methods that take a ReadOnlyMemory<T> slice the caller's memory directly.
Methods
EnumerateRecords(ReadOnlyMemory<byte>)
Reads ISO 8211 records one at a time, without building a whole document.
public static IEnumerable<Iso8211Record> EnumerateRecords(ReadOnlyMemory<byte> data)
Parameters
dataReadOnlyMemory<byte>The ISO 8211 data to read.
Returns
- IEnumerable<Iso8211Record>
The records in file order, the Data Descriptive Record (DDR) first. Records are read as the sequence is enumerated, so a record that has been processed can be released.
Examples
byte[] data = File.ReadAllBytes("path/to/file.000");
Iso8211DataDescriptiveRecord? ddr = null;
foreach (Iso8211Record record in Iso8211DocumentReader.EnumerateRecords(data))
{
if (record.IsDataDescriptiveRecord)
{
ddr = Iso8211DataDescriptiveRecordReader.Read(record);
continue;
}
// Decode the record's fields with ddr, then let it go.
}
Remarks
Every field's Data is a slice of data, so
don't modify the memory while the records are in use.
Enumeration stops at the end of the data, or at a record that can't be read, such as one cut short by the end of the data.
Read(ref Iso8211Reader)
Reads an ISO 8211 document using an Iso8211Reader.
public static Iso8211Document Read(ref Iso8211Reader parser)
Parameters
parserIso8211ReaderThe forward-only reader to use for parsing.
Returns
- Iso8211Document
The parsed ISO 8211 document.
Remarks
The reader only exposes spans, so each field's data is copied. When you have the data as memory, Read(ReadOnlyMemory<byte>) avoids the copies.
Read(byte[])
Reads an ISO 8211 document from a byte array.
public static Iso8211Document Read(byte[] data)
Parameters
databyte[]The ISO 8211 data to read. The document is read from a copy, so the array can be reused afterwards.
Returns
- Iso8211Document
The parsed ISO 8211 document.
Read(Stream)
Reads an ISO 8211 document from a stream.
public static Iso8211Document Read(Stream stream)
Parameters
streamStreamThe stream containing ISO 8211 data.
Returns
- Iso8211Document
The parsed ISO 8211 document.
Read(ReadOnlyMemory<byte>)
Reads an ISO 8211 document from memory, without copying it.
public static Iso8211Document Read(ReadOnlyMemory<byte> data)
Parameters
dataReadOnlyMemory<byte>The ISO 8211 data to read.
Returns
- Iso8211Document
The parsed ISO 8211 document.
Remarks
Every field's Data is a slice of data, so
the document holds a reference to it. Don't modify or reuse the memory while the document
is in use. To read from a buffer you will reuse, call Read(byte[]), which
reads from a copy.
Read(ReadOnlySpan<byte>)
Reads an ISO 8211 document from a span of bytes.
public static Iso8211Document Read(ReadOnlySpan<byte> data)
Parameters
dataReadOnlySpan<byte>The ISO 8211 data to read. The document is read from a copy.
Returns
- Iso8211Document
The parsed ISO 8211 document.
ReadAsync(Stream, CancellationToken)
Asynchronously reads an ISO 8211 document from a stream.
public static Task<Iso8211Document> ReadAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamThe stream containing ISO 8211 data.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<Iso8211Document>
A task that represents the asynchronous read operation.
ReadFromFile(string)
Reads an ISO 8211 document from a file.
public static Iso8211Document ReadFromFile(string path)
Parameters
pathstringThe path to the ISO 8211 file.
Returns
- Iso8211Document
The parsed ISO 8211 document.
ReadFromFileAsync(string, CancellationToken)
Asynchronously reads an ISO 8211 document from a file.
public static Task<Iso8211Document> ReadFromFileAsync(string path, CancellationToken cancellationToken = default)
Parameters
pathstringThe path to the ISO 8211 file.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<Iso8211Document>
A task that represents the asynchronous read operation.