/// <summary> /// Reads the next file header block from tape. /// This function will continue reading tape data until it finds a header block. /// </summary> /// <returns>The header block.</returns> private DragonTapeHeaderBlock ReadHeaderBlock() { while (true) { DragonTapeBlock.Sync(Tape, 1); var block = DragonTapeBlock.ReadBlockSynced(Tape); if (block is DragonTapeHeaderBlock) { return((DragonTapeHeaderBlock)block); } } }
/// <summary> /// Reads a sequence of data blocks. /// Reads data blocks until an EOF block is encoutered. Return the combined payload from the data blocks. Assumes that the tape is located /// just following the header block. /// </summary> /// <param name="isgapped">Set if the blocks are recorded with gaps.</param> /// <returns>Data payload</returns> private byte[] ReadDataBlocks(string filename, bool isgapped) { /* Read blocks and put the block payloads into the blocks list. End when the EOF block is encountered. */ var blocks = new List <byte[]>(); var datalength = 0; var eof = false; while (!eof) { DragonTapeBlock.Sync(Tape, 0); var block = DragonTapeBlock.ReadBlockSynced(Tape); switch (block.BlockType) { case DragonTapeBlockType.Data: blocks.Add(block.Data); datalength += block.Length; break; case DragonTapeBlockType.EndOfFile: eof = true; break; default: throw new InvalidFileException(filename, String.Format("Unexpected block of type {0}", (int)block.BlockType)); } } /* Convert the individual blocks into a single byte array. */ var data = new byte[datalength]; var offset = 0; for (int i = 0; i < blocks.Count; i++) { Array.Copy(blocks[i], 0, data, offset, blocks[i].Length); offset += blocks[i].Length; } return(data); }