-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBinaryReaderExtensions.cs
More file actions
39 lines (34 loc) · 1.5 KB
/
BinaryReaderExtensions.cs
File metadata and controls
39 lines (34 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.IO;
using System.Text;
namespace X937
{
/// <summary>
/// Provides extra methods to the BinaryReader class.
/// </summary>
static public class BinaryReaderExtensions
{
/// <summary>
/// Peek ahead at an Ebcdic string without moving the position in the reader.
/// </summary>
/// <param name="reader">The reader that will be read from.</param>
/// <param name="length">The number of characters to peek ahead.</param>
/// <returns>A string that contains the ASCII encoded string represented by the data in the reader.</returns>
public static string PeekEbcdicString( this BinaryReader reader, int length )
{
var str = reader.ReadEbcdicString( length );
reader.BaseStream.Position -= length;
return str;
}
/// <summary>
/// Read an Ebcdic encoded string from the reader.
/// </summary>
/// <param name="reader">The reader that will be read from.</param>
/// <param name="length">The number of characters to peek ahead.</param>
/// <returns>A string that contains the ASCII encoded string represented by the data in the reader.</returns>
public static string ReadEbcdicString( this BinaryReader reader, int length )
{
var bytes = reader.ReadBytes( length );
return Encoding.ASCII.GetString( Encoding.Convert( Encoding.GetEncoding( "IBM037" ), Encoding.ASCII, bytes, 0, length ) );
}
}
}