private void DecodeDirectory(FileDecodingInputStream inputStream) { DirectorySegment directory = streamParser.ParseDirectory(inputStream); UpdateCurrentDirectory(directory); platform.CreateDirectory(currentDirectory); }
public void PositionPropertyTest() { byte[] data = { 0x1, 0x2, 0x3 }; using (FileDecodingInputStream stream = CreateFileDecodingInputStream(data)) { Assert.AreEqual(0, stream.Position); stream.ReadBit(out Bit _); stream.ReadBit(out Bit _); Assert.AreEqual(2, stream.Position); stream.ReadBit(out Bit _); stream.ReadBit(out Bit _); stream.ReadBit(out Bit _); stream.ReadBit(out Bit _); stream.ReadBit(out Bit _); stream.ReadBit(out Bit _); Assert.AreEqual(8, stream.Position); stream.ReadBit(out Bit _); stream.ReadBit(out Bit _); Assert.AreEqual(10, stream.Position); stream.ReadBit(out Bit _); stream.ReadBit(out Bit _); stream.ReadBit(out Bit _); Assert.AreEqual(13, stream.Position); } }
public void SizePropertyTest() { byte[] data = { 0x1, 0x2, 0x3 }; using (FileDecodingInputStream stream = CreateFileDecodingInputStream(data)) { Assert.AreEqual(3, stream.SizeInBytes); } }
public void EmptyStreamTest() { using (FileDecodingInputStream stream = CreateFileDecodingInputStream(new byte[0])) { Assert.IsTrue(stream.IsEmpty); Assert.AreEqual(0, stream.SizeInBytes); Assert.AreEqual(0, stream.Position); } }
public void DefaultsTest() { using (FileDecodingInputStream stream = CreateFileDecodingInputStream(new byte[] { 1 })) { Assert.IsFalse(stream.IsEmpty); Assert.AreEqual(1, stream.SizeInBytes); Assert.AreEqual(0, stream.Position); } }
private void DecodeFile(FileDecodingInputStream inputStream, BootstrapSegment bootstrapSegment, CancellationToken cancellationToken, IProgressHandler progressHandler) { FileSegment file = streamParser.ParseFile(inputStream, bootstrapSegment.WeightsTable); string path = Path.Combine(currentDirectory, file.Name); using (FileDecodingOutputStream outputStream = new FileDecodingOutputStream(path, platform)) { file.FileDecoder.Decode(outputStream, cancellationToken, progressHandler); } }
private byte[] Decode(byte[] code, HuffmanTreeBase tree, long streamSize) { MemoryStream outputMemoryStream = new MemoryStream(); FileDecodingInputStream inputStream = CreateFileDecodingInputStream(code); FileDecodingOutputStream outputStream = CreateFileDecodingOutputStream(outputMemoryStream); try { new HuffmanDecoder().Decode(inputStream, tree, outputStream, streamSize, CancellationToken.None, null); return(outputMemoryStream.ToArray()); } finally { inputStream.Dispose(); outputStream.Dispose(); } }
public void ReadBitTest1() { byte[] data = { 0x39, 0xCC }; using (FileDecodingInputStream stream = CreateFileDecodingInputStream(data)) { List <Bit> bitList = new List <Bit>(16); while (!stream.IsEmpty) { Assert.IsTrue(stream.ReadBit(out Bit bit)); bitList.Add(bit); } Assert.IsFalse(stream.ReadBit(out Bit _)); Assert.AreEqual("1001110000110011", TestHelper.StringFromBits(bitList.ToArray())); } }
private void Decode(string inputFile, string outputFolder, CancellationToken cancellationToken, IProgress <CodingProgressInfo> progress) { FileDecodingInputStream inputStream = new FileDecodingInputStream(inputFile, platform); ITaskProgressController tpc = CreateTaskProgressController(progress, inputStream); try { if (inputStream.IsEmpty) { return; } StreamKind code = inputStream.ReadStreamFormat(); if (code != StreamKind.WT_CODE) { throw new StreamFormatException(); } tpc.Start(); directoriesQueue.Enqueue(currentDirectory = outputFolder); BootstrapSegment bootstrapSegment = streamParser.ParseWeightsTable(inputStream); while (!inputStream.IsEmpty) { switch (inputStream.ReadStreamFormat()) { case StreamKind.FS_CODE: DecodeFile(inputStream, bootstrapSegment, cancellationToken, tpc); break; case StreamKind.DS_CODE: DecodeDirectory(inputStream); break; default: throw new StreamFormatException(); } } tpc.Finish(); } catch { tpc.Error(); throw; } finally { inputStream.Dispose(); } }
private ITaskProgressController CreateTaskProgressController(IProgress <CodingProgressInfo> progress, FileDecodingInputStream inputStream) { if (progress == null) { return(new NullTaskProgressController()); } return(new DecodingTaskProgressController(progress, inputStream.SizeInBytes)); }