本文整理汇总了C#中EndianBinaryWriter.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# EndianBinaryWriter.Seek方法的具体用法?C# EndianBinaryWriter.Seek怎么用?C# EndianBinaryWriter.Seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EndianBinaryWriter
的用法示例。
在下文中一共展示了EndianBinaryWriter.Seek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteArchive
/// <summary>
/// Creates an archive out of the specified <see cref="VirtualFilesystemDirectory"/>, optionally compressing the resulting file.
/// </summary>
/// <param name="outputPath">Filepath to which to write the file to.</param>
/// <param name="root"><see cref="VirtualFilesystemDirectory"/> to create an archive out of.</param>
/// <param name="compression">Optionally compress with Yaz0 or Yay0 compression.</param>
public static void WriteArchive(string outputPath, VirtualFilesystemDirectory root, ArchiveCompression compression = ArchiveCompression.Uncompressed)
{
if (string.IsNullOrEmpty(outputPath))
throw new ArgumentNullException("filePath", "Cannot write archive to empty file path!");
if (root == null)
throw new ArgumentNullException("root", "Cannot write null VirtualFilesystemDirectory to archive.");
Archive rarc = new Archive();
MemoryStream outputData = new MemoryStream();
// Create an archive structure from the given root and write it to file. Compression will be applied if specified.
MemoryStream uncompressedStream = new MemoryStream();
using (EndianBinaryWriter fileWriter = new EndianBinaryWriter(uncompressedStream, Endian.Big))
{
byte[] rawData = rarc.WriteFile(root);
fileWriter.Write(rawData);
fileWriter.Seek(0, SeekOrigin.Begin);
fileWriter.BaseStream.CopyTo(outputData);
}
MemoryStream compressedStream = new MemoryStream();
switch(compression)
{
case ArchiveCompression.Yay0:
throw new NotImplementedException("Yay0 Compression not implemented.");
//compressedStream = Yay0.Encode(uncompressedStream);
//break;
case ArchiveCompression.Yaz0:
EndianBinaryWriter encoded = Yaz0.Encode(uncompressedStream);
encoded.Seek(0, SeekOrigin.Begin);
encoded.BaseStream.CopyTo(compressedStream);
break;
case ArchiveCompression.Uncompressed:
// Well, that was easy.
compressedStream = uncompressedStream;
break;
}
compressedStream.Seek(0, SeekOrigin.Begin);
compressedStream.WriteTo(File.Create(outputPath));
}