本文整理汇总了C#中Stream.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.Seek方法的具体用法?C# Stream.Seek怎么用?C# Stream.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.Seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalWrite
protected override void InternalWrite(Stream Target)
{
Target.Seek(0, SeekOrigin.Begin);
Target.Write(ByteHelper.StringToByte("ID3"));
// Version 3.0 Flags dummy size
Target.Write(new byte[] { 3,0, 0, 0, 0, 0, 0 }, 0, 7);
long totalFrameSize = 0;
Stream frameStream = null;
foreach(Frame f in Frames)
{
frameStream = FrameObjectToByteArray(f);
totalFrameSize += frameStream.Length;
frameStream.CopyTo(Target);
frameStream.Flush();
}
Target.Seek(6, SeekOrigin.Begin);
Target.Write(ByteHelper.GetByteArrayWith7SignificantBitsPerByteForInt((int)totalFrameSize));
// frame fertig geschrieben jetzt müssen die daten rein =>
// sourcestream an die stelle spulen und lesen bis endpos
Target.Seek(DataStart, SeekOrigin.Begin);
// Target.Copy(SourceStream, DataStart, DataEnd);
Target.Flush();
Target.Close();
}
示例2: WriteToWav
public static void WriteToWav(Stream RawData, Stream Output, AudioFormat AudioFormat)
{
if (AudioFormat.WaveFormat != WaveFormatType.Pcm) throw new ArgumentException("You can write only to WAV.");
BinaryWriter bwOutput = new BinaryWriter(Output);
//WAV header
bwOutput.Write("RIFF".ToCharArray());
bwOutput.Write((uint)(RawData.Length + 36));
bwOutput.Write("WAVE".ToCharArray());
bwOutput.Write("fmt ".ToCharArray());
bwOutput.Write((uint)0x10);
bwOutput.Write((ushort)0x01);
bwOutput.Write((ushort)AudioFormat.Channels);
bwOutput.Write((uint)AudioFormat.SamplesPerSecond);
bwOutput.Write((uint)(AudioFormat.BitsPerSample * AudioFormat.SamplesPerSecond * AudioFormat.Channels / 8));
bwOutput.Write((ushort)(AudioFormat.BitsPerSample * AudioFormat.Channels / 8));
bwOutput.Write((ushort)AudioFormat.BitsPerSample);
bwOutput.Write("data".ToCharArray());
bwOutput.Write((uint)RawData.Length);
long originalRawDataStreamPosition = RawData.Position;
RawData.Seek(0, SeekOrigin.Begin);
byte[] buffer = new byte[4096];
int read;
while ((read = RawData.Read(buffer, 0, 4096)) > 0)
{
bwOutput.Write(buffer, 0, read);
}
RawData.Seek(originalRawDataStreamPosition, SeekOrigin.Begin);
}
示例3: CreateV1Frames
private void CreateV1Frames(Stream stream)
{
// ID1 header am ende ...
stream.Seek(-125, SeekOrigin.End);
// 30 zeichen title => TIT2
// 30 zeichen artist => TCOM
// 30 zeichen album => TALB
// 4 zeichen jahr => TYER
// 30 zeichen commentar - kann auch den track enthalten (TRCK) - der letzte byte
// 1 byte Genre
// == 125
foreach (var item in new[] { "TIT2", "TCOM", "TALB" })
{
AddFrame(item, ByteHelper.BytesToString(stream.Read(30)));
}
AddFrame("TYER", ByteHelper.BytesToString(stream.Read(4)));
// comment - egal
stream.Seek(28, SeekOrigin.Current);
var track = stream.Read(2);
if (track[0] == 0 && track[1] != 0)
{
// dann ist track[1] eine zahl;
if (track[1] < 48)
{
AddFrame("TRCK",((int)track[1]).ToString());
}
}
}
示例4: CopyStream
public static void CopyStream(Stream source, Stream dest, bool rewindSource)
{
long restorePosition1 = -1;
if (source.CanSeek)
{
restorePosition1 = source.Position;
if (rewindSource)
source.Seek(0, SeekOrigin.Begin);
}
else
{
if (rewindSource)
throw new Exception("Can't rewind source");
}
byte[] buffer = new byte[bufferSize];
int readAmount;
int readOffset = 0;
while ((readAmount = source.Read(buffer, readOffset, bufferSize)) > 0)
{
dest.Write(buffer, 0, readAmount);
}
if (source.CanSeek)
source.Seek(restorePosition1, SeekOrigin.Begin);
}
示例5: GetPEFileKinds
private static PEFileKinds GetPEFileKinds(Stream s)
{
var rawPeSignatureOffset = new byte[4];
s.Seek(0x3c, SeekOrigin.Begin);
s.Read(rawPeSignatureOffset, 0, 4);
int peSignatureOffset = rawPeSignatureOffset[0];
peSignatureOffset |= rawPeSignatureOffset[1] << 8;
peSignatureOffset |= rawPeSignatureOffset[2] << 16;
peSignatureOffset |= rawPeSignatureOffset[3] << 24;
var coffHeader = new byte[24];
s.Seek(peSignatureOffset, SeekOrigin.Begin);
s.Read(coffHeader, 0, 24);
byte[] signature = { (byte)'P', (byte)'E', (byte)'\0', (byte)'\0' };
for (int index = 0; index < 4; index++)
{
if (coffHeader[index] != signature[index]) throw new InvalidOperationException("Attempted to check a non PE file for the console subsystem!");
}
var subsystemBytes = new byte[2];
s.Seek(68, SeekOrigin.Current);
s.Read(subsystemBytes, 0, 2);
int subSystem = subsystemBytes[0] | subsystemBytes[1] << 8;
return
// http://support.microsoft.com/kb/90493
subSystem == 3 ? PEFileKinds.ConsoleApplication :
subSystem == 2 ? PEFileKinds.WindowApplication :
PEFileKinds.Dll; /*IMAGE_SUBSYSTEM_WINDOWS_CUI*/
}
示例6: WriteDataCommand
public void WriteDataCommand(Stream source, long offset, long length)
{
writer.Write(BinaryFormat.DataCommand);
writer.Write(length);
var originalPosition = source.Position;
try
{
source.Seek(offset, SeekOrigin.Begin);
var buffer = new byte[1024 * 1024];
int read;
do
{
read = source.Read(buffer, 0, buffer.Length);
writer.Write(buffer, 0, read);
} while (read > 0);
}
finally
{
source.Seek(originalPosition, SeekOrigin.Begin);
}
}
示例7: Open
public bool Open(Stream fs)
{
Header = MarshalUtil.ReadStruct<CBMD>(fs); //read header
//-- Graphics Reading --
//Read ahead the size of the uncompressed file
fs.Seek(Header.CompressedCGFXOffset + 1, SeekOrigin.Begin);
var intBytes = new byte[4];
fs.Read(intBytes, 0, 4);
DecompressedCGFX = new byte[BitConverter.ToUInt32(intBytes, 0)];
//Read again from the start
fs.Seek(Header.CompressedCGFXOffset, SeekOrigin.Begin);
var ms = new MemoryStream(DecompressedCGFX);
try
{
var lz11 = new DSDecmp.Formats.Nitro.LZ11();
lz11.Decompress(fs, Header.CBMDLength - fs.Position, ms);
}
catch
{ //might throw exception if size of compressed is bigger than it should be
}
ms.Seek(0, SeekOrigin.Begin);
CGFXContext = new CGFXContext();
CGFXContext.Open(ms);
return true;
}
示例8: getSSMBase
public static string getSSMBase(Stream imageStream)
{
byte[] byc = new byte[4];
long highlimit = 5000000;
long lowlimit = 100000;
long difflimit = 100000;
if (imageStream.Length < highlimit)
highlimit = imageStream.Length;
for (long i = lowlimit; i < highlimit; i += 4)
{
long start = i;
imageStream.Seek(i, SeekOrigin.Begin);
if (SSMBaseRecursion(imageStream, i, 0, 0, difflimit))
return start.ToString("X");
else
continue;
}
difflimit += 40000;
for (long i = lowlimit; i < highlimit; i += 4)
{
long start = i;
imageStream.Seek(i, SeekOrigin.Begin);
if (SSMBaseRecursion(imageStream, i, 0, 0, difflimit))
return start.ToString("X");
else
continue;
}
return "Enter SSM Base";
}
示例9: ParseIndex
private void ParseIndex(Stream stream, int i)
{
using (var br = new BinaryReader(stream))
{
stream.Seek(-12, SeekOrigin.End);
int count = br.ReadInt32();
stream.Seek(0, SeekOrigin.Begin);
if (count * (16 + 4 + 4) > stream.Length)
throw new Exception("ParseIndex failed");
for (int j = 0; j < count; ++j)
{
byte[] key = br.ReadBytes(16);
if (key.IsZeroed()) // wtf?
key = br.ReadBytes(16);
if (key.IsZeroed()) // wtf?
throw new Exception("key.IsZeroed()");
IndexEntry entry = new IndexEntry();
entry.Index = i;
entry.Size = br.ReadInt32BE();
entry.Offset = br.ReadInt32BE();
CDNIndexData.Add(key, entry);
}
}
}
示例10: FromStream
public void FromStream(Stream stream, int size)
{
long start = stream.Position;
BinaryReader reader = new BinaryReader(stream, Encoding.ASCII);
ushort magic = reader.ReadUInt16();
stream.Seek(start, SeekOrigin.Begin);
_optionalHeaderBase = null;
switch (magic)
{
case Constants.IMAGE_NT_OPTIONAL_HDR32_MAGIC:
_optionalHeaderBase = new OptionalHeaderPE32();
break;
case Constants.IMAGE_NT_OPTIONAL_HDR64_MAGIC:
_optionalHeaderBase = new OptionalHeaderPE64();
break;
case Constants.IMAGE_ROM_OPTIONAL_HDR_MAGIC:
//_optionalHeaderBase = new OptionalHeaderPE32();
//break;
default:
break;
}
if (_optionalHeaderBase != null)
{
_optionalHeaderBase.FromStream(stream);
}
stream.Seek(start + size, SeekOrigin.Begin);
}
示例11: Packfile
public Packfile(Stream stream, bool isStr2)
{
IsStr2 = isStr2;
stream.Seek(0, SeekOrigin.Begin);
FileData = stream.ReadStruct<PackfileFileData>();
m_Files = new List<IPackfileEntry>();
uint runningPosition = 0;
List<PackfileEntryFileData> entryFileData = new List<PackfileEntryFileData>();
for (int i = 0; i < FileData.NumFiles; i++)
{
PackfileEntryFileData data = stream.ReadStruct<PackfileEntryFileData>();
if (IsCondensed && IsCompressed)
{
data.Flags = 0;
data.Start = runningPosition;
runningPosition += data.Size;
}
else if (IsCondensed)
{
data.Start = runningPosition;
runningPosition += data.Size.Align(16);
}
entryFileData.Add(data);
}
for (int i = 0; i < FileData.NumFiles; i++)
{
stream.Align(2);
string filename = stream.ReadAsciiNullTerminatedString();
stream.Seek(1, SeekOrigin.Current);
m_Files.Add(new PackfileEntry(this, entryFileData[i], filename));
stream.Align(2);
}
if (IsCondensed && IsCompressed)
{
DataOffset = 0;
byte[] compressedData = new byte[FileData.CompressedDataSize];
stream.Read(compressedData, 0, (int)FileData.CompressedDataSize);
using (MemoryStream tempStream = new MemoryStream(compressedData))
{
using (Stream s = new ZlibStream(tempStream, CompressionMode.Decompress, true))
{
byte[] uncompressedData = new byte[FileData.DataSize];
s.Read(uncompressedData, 0, (int)FileData.DataSize);
DataStream = new MemoryStream(uncompressedData);
}
}
}
else
{
DataStream = stream;
DataOffset = stream.Position;
}
}
示例12: Deserialize
public static ISavegame Deserialize(Stream stream)
{
if (stream == null) throw new ArgumentNullException(nameof(stream));
if (stream.Position != 0)
stream.Seek(0, SeekOrigin.Begin);
var checkBuffer = new byte[2];
stream.Read(checkBuffer, 0, 2);
stream.Seek(0, SeekOrigin.Begin);
if (checkBuffer.SequenceEqual(new byte[] {0x1f, 0x8b}))
{
using (var gZipStream = new GZipStream(stream, CompressionMode.Decompress))
{
using (var memoryStream = new MemoryStream())
{
gZipStream.CopyTo(memoryStream);
return Deserialize(Encoding.UTF8.GetString(memoryStream.ToArray()));
}
}
}
if (stream is MemoryStream)
{
var memoryStream = (MemoryStream) stream;
return Deserialize(Encoding.UTF8.GetString(memoryStream.ToArray()));
}
using (var memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
return Deserialize(Encoding.UTF8.GetString(memoryStream.ToArray()));
}
}
示例13: Load
public unsafe MultiIcon Load(Stream stream)
{
stream.Position = 0;
SingleIcon singleIcon = new SingleIcon("Untitled");
ICONDIR iconDir = new ICONDIR(stream);
if (iconDir.idReserved != 0)
throw new InvalidMultiIconFileException();
if (iconDir.idType != 1)
throw new InvalidMultiIconFileException();
int entryOffset = sizeof(ICONDIR);
// Add Icon Images one by one to the new entry created
for(int i=0; i<iconDir.idCount; i++)
{
stream.Seek(entryOffset, SeekOrigin.Begin);
ICONDIRENTRY entry = new ICONDIRENTRY(stream);
// If there is missing information in the header... lets try to calculate it
entry = CheckAndRepairEntry(entry);
stream.Seek(entry.dwImageOffset, SeekOrigin.Begin);
singleIcon.Add(new IconImage(stream, (int) (stream.Length - stream.Position)));
entryOffset += sizeof(ICONDIRENTRY);
}
return new MultiIcon(singleIcon);
}
示例14: Deserialize
public void Deserialize(Stream input)
{
input.Seek(0, SeekOrigin.Begin);
var header = input.ReadStructure<SimGroup.FileHeader>();
if (header.HeaderSize < Marshal.SizeOf(header) ||
header.HeaderSize > input.Length)
{
throw new FormatException("bad data size");
}
uint[] unknown08s = new uint[header.Unknown14Count];
input.Seek(header.Unknown08Offset, SeekOrigin.Begin);
for (ushort i = 0; i < header.Unknown14Count; i++)
{
unknown08s[i] = input.ReadValueU32();
}
input.Seek(header.Unknown0COffset, SeekOrigin.Begin);
for (ushort i = 0; i < header.Unknown16Count; i++)
{
}
}
示例15: Load
public void Load(Stream data, bool fast = false)
{
uint headersize = Helpers.ReadLEUInt(data);
long startoffset = data.Position;
Header = new HeaderStruct();
Header.magic = Helpers.ReadLEUInt(data);
Header.totalCount = Helpers.ReadLEUInt(data);
Header.ebxCount = Helpers.ReadLEUInt(data);
Header.resCount = Helpers.ReadLEUInt(data);
Header.chunkCount = Helpers.ReadLEUInt(data);
Header.stringOffset = Helpers.ReadLEUInt(data);
Header.chunkMetaOffset = Helpers.ReadLEUInt(data);
Header.chunkMetaSize = Helpers.ReadLEUInt(data);
ReadSha1List(data);
ReadEbxList(data);
ReadResList(data);
ReadChunkList(data);
if (Header.chunkCount != 0)
ChunkMeta = BJSON.ReadField(data);
else
ChunkMeta = null;
data.Seek(startoffset + Header.stringOffset, 0);
ReadEbxListNames(data);
data.Seek(startoffset + Header.stringOffset, 0);
ReadResListNames(data);
data.Seek(startoffset + headersize, 0);
ReadEbxListData(data, fast);
ReadResListData(data, fast);
ReadChunkListData(data, fast);
ApplySHA1s();
}