diff --git a/KaitaiStream.cs b/KaitaiStream.cs index 013517e..ee0ebe6 100644 --- a/KaitaiStream.cs +++ b/KaitaiStream.cs @@ -8,7 +8,7 @@ namespace Kaitai { /// /// The base Kaitai stream which exposes an API for the Kaitai Struct framework. - /// It's based off a BinaryReader, which is a little-endian reader. + /// It's based off a BinaryReader, which is a little-endian reader. /// public partial class KaitaiStream : BinaryReader { @@ -22,7 +22,7 @@ public KaitaiStream(Stream stream) : base(stream) } /// - /// Create a KaitaiStream backed by a closed file (in read-only binary-mode). + /// Create a KaitaiStream by opening a file in read-only binary mode (FileStream). /// public KaitaiStream(string filename) : base(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { @@ -36,23 +36,26 @@ public KaitaiStream(byte[] data) : base(new MemoryStream(data)) } /// - /// Used internally. + /// Temporary 64-bit buffer for leftover bits left from an unaligned bit + /// read operation. Following unaligned bit operations would consume bits + /// left in this buffer first, and then, if needed, would continue + /// consuming bytes from the stream. /// private ulong Bits = 0; /// - /// Used internally. + /// Number of bits left in Bits buffer. /// private int BitsLeft = 0; /// - /// Used internally. - /// Caches the current plaftorm endianness and allows emited bytecode to be optimised. Thanks to @Arlorean. + /// Caches the current platform endianness and allows emitted bytecode to be optimized. Thanks to @Arlorean. + /// https://github.com/kaitai-io/kaitai_struct_csharp_runtime/pull/9 /// static readonly bool IsLittleEndian = BitConverter.IsLittleEndian; static KaitaiStream() { - compute_single_rotations(); + computeSingleRotations(); } #endregion @@ -61,7 +64,7 @@ static KaitaiStream() /// /// Check if the stream position is at the end of the stream (at EOF). - /// WARNING: This requires a seekable and tellable stream. + /// WARNING: This requires a stream that supports seeking (memory-based or file-based). /// public bool IsEof { @@ -70,7 +73,7 @@ public bool IsEof /// /// Move the stream to a specified absolute position. - /// WARNING: This requires a seekable stream. + /// WARNING: This requires a stream that supports seeking (memory-based or file-based). /// /// The position to seek to, as non-negative integer public void Seek(long position) @@ -80,7 +83,7 @@ public void Seek(long position) /// /// Get the current position within the stream. - /// WARNING: This requires a tellable stream. + /// WARNING: This requires a stream that supports seeking (memory-based or file-based). /// public long Pos { @@ -89,7 +92,7 @@ public long Pos /// /// Get the total length of the stream (ie. file size). - /// WARNING: This requires a seekable and tellable stream. + /// WARNING: This requires a stream that supports seeking (memory-based or file-based). /// public long Size { @@ -518,7 +521,7 @@ public byte[] ProcessXor(byte[] data, byte[] key) { if (key.Length == 1) return ProcessXor(data, key[0]); - if (key.Length <= 64 && ByteArrayZero(key)) + if (key.Length <= 64 && IsByteArrayZero(key)) return data; int dl = data.Length; @@ -535,14 +538,14 @@ public byte[] ProcessXor(byte[] data, byte[] key) /// /// Used internally. /// - private static byte[][] precomputed_single_rotations; + private static byte[][] precomputedSingleRotations; /// /// Used internally. /// - private static void compute_single_rotations() + private static void computeSingleRotations() { - precomputed_single_rotations = new byte[8][]; + precomputedSingleRotations = new byte[8][]; for (int amount = 1; amount < 8; amount++) { byte[] translate = new byte[256]; @@ -551,7 +554,7 @@ private static void compute_single_rotations() // formula taken from: http://stackoverflow.com/a/812039 translate[i] = (byte) ((i << amount) | (i >> (8 - amount))); } - precomputed_single_rotations[amount] = translate; + precomputedSingleRotations[amount] = translate; } } @@ -566,7 +569,7 @@ private static void compute_single_rotations() public byte[] ProcessRotateLeft(byte[] data, int amount, int groupSize) { if (groupSize < 1) - throw new Exception("group size must be at least 1 to be valid"); + throw new ArgumentException("group size must be at least 1 to be valid", "groupSize"); amount = Mod(amount, groupSize * 8); if (amount == 0) @@ -578,7 +581,7 @@ public byte[] ProcessRotateLeft(byte[] data, int amount, int groupSize) if (groupSize == 1) { - byte[] translate = precomputed_single_rotations[amount]; + byte[] translate = precomputedSingleRotations[amount]; for (int i = 0; i < dl; i++) { @@ -751,7 +754,7 @@ public static bool ByteArrayEqual(byte[] a, byte[] b) /// /// Check if byte array is all zeroes. /// - public static bool ByteArrayZero(byte[] a) + public static bool IsByteArrayZero(byte[] a) { foreach (byte x in a) if (x != 0)