本文整理汇总了C#中File.ReadBlock方法的典型用法代码示例。如果您正苦于以下问题:C# File.ReadBlock方法的具体用法?C# File.ReadBlock怎么用?C# File.ReadBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File.ReadBlock方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tag
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="Tag" /> by reading the contents from a specified
/// position in a specified file.
/// </summary>
/// <param name="file">
/// A <see cref="File" /> object containing the file from
/// which the contents of the new instance is to be read.
/// </param>
/// <param name="position">
/// A <see cref="long" /> value specify at what position to
/// read the tag.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="file" /> is <see langword="null" />.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="position" /> is less than zero or greater
/// than the size of the file.
/// </exception>
/// <exception cref="CorruptFileException">
/// The file does not contain <see cref="FileIdentifier" />
/// at the given position.
/// </exception>
public Tag (File file, long position)
{
if (file == null)
throw new ArgumentNullException ("file");
file.Mode = TagLib.File.AccessMode.Read;
if (position < 0 ||
position > file.Length - Size)
throw new ArgumentOutOfRangeException (
"position");
file.Seek (position);
// read the tag -- always 128 bytes
ByteVector data = file.ReadBlock ((int) Size);
// some initial sanity checking
if (!data.StartsWith (FileIdentifier))
throw new CorruptFileException (
"ID3v1 data does not start with identifier.");
Parse (data);
}
示例2: ReadSize
private ulong ReadSize(File file, ref uint packetSizeLength, ref bool eof)
{
uint tmp;
ulong size = 0;
do
{
ByteVector b = file.ReadBlock(1);
if (b.IsEmpty)
{
eof = true;
break;
}
tmp = b.ToUInt();
size = (size << 7) | (tmp & 0x7F);
packetSizeLength++;
} while ((tmp & 0x80) == 1);
return size;
}
示例3: ReadSv8Properties
private void ReadSv8Properties(File file)
{
bool foundSH = false;
while (!foundSH)
{
ByteVector packetType = file.ReadBlock(2);
uint packetSizeLength = 0;
bool eof = false;
ulong packetSize = ReadSize(file, ref packetSizeLength, ref eof);
if (eof)
{
break;
}
ulong payloadSize = packetSize - 2 - packetSizeLength;
ByteVector data = file.ReadBlock((int)payloadSize);
if (packetType == "SH")
{
foundSH = true;
if (payloadSize <= 5)
{
break;
}
int pos = 4;
version = data[pos];
pos += 1;
frames = (uint)ReadSize(data, ref pos);
if (pos > (uint)payloadSize - 3)
{
break;
}
ulong beginSilence = ReadSize(data, ref pos);
if (pos > (uint)payloadSize - 2)
{
break;
}
ushort flags = data.Mid(pos, 1).ToUShort(true);
sample_rate = sftable[(flags >> 13) & 0x07];
channels = ((flags >> 4) & 0x0F) + 1;
framecount = frames - beginSilence;
}
else if (packetType == "SE")
{
break;
}
else
{
file.Seek((int)payloadSize, SeekOrigin.Current);
}
}
}
示例4: StreamHeader
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="StreamHeader" /> for a specified header block and
/// stream length.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector" /> object containing the stream
/// header data.
/// </param>
/// <param name="streamLength">
/// A <see cref="long" /> value containing the length of the
/// MusePAck stream in bytes.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="data" /> is <see langword="null" />.
/// </exception>
/// <exception cref="CorruptFileException">
/// <paramref name="data" /> does not begin with <see
/// cref="FileIdentifierSv7" /> or with <see
/// cref="FileIdentifierSv8" /> or is less than
/// <see cref="Size" /> bytes long.
/// </exception>
public StreamHeader(File file, long streamLength)
{
if (file == null)
throw new ArgumentNullException ("file");
// Assign default values, to be able to call methods
// in the constructor
stream_length = streamLength;
version = 7;
header_data = 0;
frames = 0;
sample_rate = 0;
channels = 2;
framecount = 0;
file.Seek(0);
ByteVector magic = file.ReadBlock(4);
if (magic.StartsWith(FileIdentifierSv7))
// SV7 Format has a fixed Header size
ReadSv7Properties(magic + file.ReadBlock((int)SizeSV7 - 4));
else if (magic.StartsWith(FileIdentifierSv8))
// for SV8 the properties need to be read from
// packet information inside the file
ReadSv8Properties(file);
else
throw new CorruptFileException(
"Data does not begin with identifier.");
}