public Block(BlockType type, ByteVector data) { if (data == null) { throw new ArgumentNullException("data"); } this.header = new BlockHeader(type, (uint) data.Count); this.data = data; }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="Block" /> with a specified header and internal /// data. /// </summary> /// <param name="header"> /// A <see cref="BlockHeader" /> object containing the /// header to use for the new instance. /// </param> /// <param name="data"> /// A <see cref="ByteVector" /> object containing the data /// to be contained in the new instance. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="data" /> is <see langword="null" />. /// </exception> /// <exception cref="CorruptFileException"> /// The size of <paramref name="data" /> does not match the /// size specified in <paramref name="header" />. /// </exception> public Block (BlockHeader header, ByteVector data) { if (data == null) throw new ArgumentNullException ("data"); if (header.BlockSize != data.Count) throw new CorruptFileException ( "Data count not equal to block size."); this.header = header; this.data = data; }
private IList<Block> ReadBlocks(ref long start, out long end, BlockMode mode, params BlockType[] types) { BlockHeader header; List<Block> list = new List<Block>(); long num = base.Find("fLaC", start); if (num < 0L) { throw new CorruptFileException("FLAC stream not found at starting position."); } end = start = num + 4L; base.Seek(start); do { header = new BlockHeader(base.ReadBlock(4)); bool flag = false; foreach (BlockType type in types) { if (header.BlockType == type) { flag = true; break; } } if (((mode == BlockMode.Whitelist) && flag) || ((mode == BlockMode.Blacklist) && !flag)) { list.Add(new Block(header, base.ReadBlock((int) header.BlockSize))); } else { base.Seek((long) header.BlockSize, SeekOrigin.Current); } end += header.BlockSize + 4; } while (!header.IsLastBlock); return list; }
/// <summary> /// Reads all metadata blocks starting from the current /// instance, starting at a specified position. /// </summary> /// <param name="start"> /// A <see cref="long" /> value reference specifying the /// position at which to start searching for the blocks. This /// will be updated to the position of the first block. /// </param> /// <param name="end"> /// A <see cref="long" /> value reference updated to the /// position at which the last block ends. /// </param> /// <param name="mode"> /// A <see cref="BlockMode" /> value indicating whether to /// white-list or black-list the contents of <paramref /// name="types" />. /// </param> /// <param name="types"> /// A <see cref="BlockType[]" /> containing the types to look /// for or not look for as specified by <paramref name="mode" /// />. /// </param> /// <returns> /// A <see cref="T:System.Collections.Generic.IList`1" /> object containing the blocks /// read from the current instance. /// </returns> /// <exception cref="CorruptFileException"> /// "<c>fLaC</c>" could not be found. /// </exception> private IList<Block> ReadBlocks(ref long start, out long end, BlockMode mode, params BlockType[] types) { List<Block> blocks = new List<Block> (); long start_position = Find ("fLaC", start); if (start_position < 0) throw new CorruptFileException ( "FLAC stream not found at starting position."); end = start = start_position + 4; Seek (start); BlockHeader header; do { header = new BlockHeader (ReadBlock ((int) BlockHeader.Size)); bool found = false; foreach (BlockType type in types) if (header.BlockType == type) { found = true; break; } if ((mode == BlockMode.Whitelist && found) || (mode == BlockMode.Blacklist && !found)) blocks.Add (new Block (header, ReadBlock ((int) header.BlockSize))); else Seek (header.BlockSize, System.IO.SeekOrigin.Current); end += header.BlockSize + BlockHeader.Size; } while (!header.IsLastBlock); return blocks; }