Пример #1
0
		/// <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;
		}
Пример #2
0
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="Block" /> with of a specified type and internal
		///    data.
		/// </summary>
		/// <param name="type">
		///    A <see cref="BlockType" /> value indicating the type of
		///    data stored in <paramref name="data" />.
		/// </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>
		public Block (BlockType type, ByteVector data)
		{
			if (data == null)
				throw new ArgumentNullException ("data");
			
			header = new BlockHeader (type, (uint) data.Count);
			
			this.data = data;
		}
Пример #3
0
		/// <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;
		}