本文整理汇总了C#中SevenZip.SevenZipExtractor.ExtractFile方法的典型用法代码示例。如果您正苦于以下问题:C# SevenZipExtractor.ExtractFile方法的具体用法?C# SevenZipExtractor.ExtractFile怎么用?C# SevenZipExtractor.ExtractFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SevenZip.SevenZipExtractor
的用法示例。
在下文中一共展示了SevenZipExtractor.ExtractFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractBytes
public static byte[] ExtractBytes(byte[] data)
{
Inits.EnsureBinaries();
using (var inStream = new MemoryStream(data))
{
using (var outStream = new MemoryStream())
{
try
{
using (var extract = new SevenZipExtractor(inStream))
{
extract.ExtractFile(0, outStream);
return outStream.ToArray();
}
}
catch
{
try
{
return SevenZipExtractor.ExtractBytes(inStream.ToArray());
}
catch { return null; }
}
}
}
}
示例2: docxParser
public static String docxParser(String filename)
{
//path to the systems temporary folder
String tempFolderPath = Path.GetTempPath();
//set the path of the 7z.dll (it needs to be in the debug folder)
SevenZipExtractor.SetLibraryPath("7z.dll");
SevenZipExtractor extractor = new SevenZipExtractor(filename);
//create a filestream for the file we are going to extract
FileStream f = new FileStream(tempFolderPath + "document.xml", FileMode.Create);
//extract the document.xml
extractor.ExtractFile("word\\document.xml", f);
//get rid of the object because it is unmanaged
extractor.Dispose();
//close the filestream
f.Close();
//send document.xml that we extracted from the .docx to the xml parser
String result = XMLParser.Parser.ParseXMLtoString(tempFolderPath + "document.xml");
//delete the extracted file from the temp folder
File.Delete(tempFolderPath + "document.xml");
return result;
}
示例3: TickReader
public TickReader(FileInfo file)
{
Serializer = new PbTickSerializer();
Codec = new QuantBox.Data.Serializer.V2.PbTickCodec();
_stream = new MemoryStream();
_originalLength = (int)file.Length;
// 加载文件,支持7z解压
var fileStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
{
try
{
using (var zip = new SevenZipExtractor(fileStream))
{
zip.ExtractFile(0, _stream);
_stream.Seek(0, SeekOrigin.Begin);
}
}
catch
{
_stream = fileStream;
_stream.Seek(0, SeekOrigin.Begin);
}
}
}
示例4: Decompress
public int Decompress(PointCloudTile tile, byte[] compressedBuffer, int count, byte[] uncompressedBuffer)
{
MemoryStream uncompressedStream = new MemoryStream(uncompressedBuffer);
MemoryStream compressedStream = new MemoryStream(compressedBuffer, 0, count, false);
using (SevenZipExtractor extractor = new SevenZipExtractor(compressedStream))
{
extractor.ExtractFile(0, uncompressedStream);
}
return (int)uncompressedStream.Position;
}
示例5: TestRead
public void TestRead()
{
var file = new FileInfo("TickDataV1_1");
using (var stream = new MemoryStream())
using (var fileStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var zip = new SevenZipExtractor(fileStream)) {
zip.ExtractFile(0, stream);
stream.Seek(0, SeekOrigin.Begin);
var serializer = new PbTickSerializer();
var codec = new PbTickCodec();
foreach (var tick in serializer.Read(stream)) {
}
}
}
示例6: Extract
public void Extract(string archivePath, string filePath, string destFilePath)
{
using (var destFileStream = new FileStream(destFilePath, FileMode.Create, FileAccess.Write))
{
this.SetLibraryPath();
var extractor = new SevenZipExtractor(archivePath);
extractor.ExtractionFinished += this.ExtractionFinished;
extractor.ExtractFile(filePath, destFileStream);
destFileStream.Flush();
destFileStream.Close();
}
}
示例7: ExtractFile
private void ExtractFile( SevenZipExtractor extractor, ManifestFile file)
{
using (var destFileStream = new FileStream(file.InstallPath, FileMode.Create, FileAccess.Write))
{
try
{
extractor.ExtractFile(file.File, destFileStream);
}
catch (Exception exception)
{
}
destFileStream.Flush();
destFileStream.Close();
}
}
示例8: DecompressBytes
public static byte[] DecompressBytes(byte[] data)
{
byte[] uncompressedbuffer = null;
using (MemoryStream compressedbuffer = new MemoryStream(data))
{
using (SevenZipExtractor extractor = new SevenZipExtractor(compressedbuffer))
{
using (MemoryStream msout = new MemoryStream())
{
extractor.ExtractFile(0, msout);
uncompressedbuffer = msout.ToArray();
}
}
}
return uncompressedbuffer;
}
示例9: extractArchive
public static int extractArchive(string inFileName, string extractPath)
{
// extract input archive
FileStream fileStream;
SevenZipExtractor extractor = null;
try
{
extractor = new SevenZipExtractor(File.OpenRead(inFileName));
foreach (var fileName in extractor.ArchiveFileNames)
{
// you of course can extract to a file stream instead of a memory stream if you want :)
//var memoryStream = new MemoryStream();
//extractor.ExtractFile(fileName, memoryStream);
// do what you want with your file here :)
fileStream = File.Create(Path.Combine(extractPath, fileName));
extractor.ExtractFile(fileName, fileStream);
int buffersize = 1024;
byte[] buffer = new byte[buffersize];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffersize)) != 0)
{
fileStream.Write(buffer, 0, bytesRead);
} // end while
fileStream.Close();
}
extractor.Dispose();
}
catch (Exception ex)
{
Logger.Logwrite(ex.Message);
Console.Error.WriteLine("Error: Could not open input archive: " + inFileName);
Console.Error.WriteLine("\t" + ex.Message);
}
finally
{
}
return 1;
}
示例10: Extract
public Stream Extract(string archivePath, string filePath)
{
this.SetLibraryPath();
var extractor = new SevenZipExtractor(archivePath);
extractor.ExtractionFinished += this.ExtractionFinished;
var stream = new MemoryStream();
var matchingfile = extractor.ArchiveFileData.Where(x => x.FileName == filePath).FirstOrDefault();
extractor.ExtractFile(matchingfile.Index, stream);
// reset stream position to the start
stream.Position = 0;
return stream;
}
示例11: ExtractFile
static byte[] ExtractFile(string archive, string file)
{
if (!archive.ToLower().EndsWith("sdz") && !archive.ToLower().EndsWith("sd7")) throw new ArgumentException("Invalid archive name");
var stream = new MemoryStream();
var format = archive.EndsWith("sdz") ? InArchiveFormat.Zip : InArchiveFormat.SevenZip;
// extract the file synchronously
var thread = new Thread(() =>
{
using (var extractor = new SevenZipExtractor(File.OpenRead(archive), format)) {
extractor.ExtractFile(file, stream, true);
}
});
thread.Start();
thread.Join();
stream.Position = 0;
return stream.ToArray();
}
示例12: LoadBook
public static Book LoadBook(string path)
{
Book book;
book = new Book() {
Name = Path.GetFileName(path),
FilePath = path,
Pages = new List<Page>()
};
SevenZipExtractor.SetLibraryPath(@"C:\Program Files (x86)\7-Zip\7z.dll");
using (var zip = new SevenZipExtractor(path))
{
foreach (var file in zip.ArchiveFileData)
{
try
{
var s = new MemoryStream();
zip.ExtractFile(file.FileName, s);
Image image = new Bitmap(s);
var page = new Page();
page.Name = file.FileName;
page.Display = image;
book.Pages.Add(page);
}
catch (Exception e)
{
}
}
}
book.Pages = book.Pages.OrderBy(p => p.Name).ToList();
return book;
}
示例13: Decompress
/// <summary>
/// 解压字节数组
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static byte[] Decompress(byte[] input)
{
byte[] uncompressedbuffer = null;
using (MemoryStream msin = new MemoryStream(input))
{
msin.Position = 0;
using (SevenZipExtractor extractor = new SevenZipExtractor(msin))
{
using (MemoryStream msout = new MemoryStream())
{
extractor.ExtractFile(0, msout);
msout.Position = 0;
uncompressedbuffer = new byte[msout.Length];
msout.Read(uncompressedbuffer, 0, uncompressedbuffer.Length);
}
}
}
return uncompressedbuffer;
}
示例14: ReadOneFile
public List<QuantBox.Data.Serializer.V2.PbTickView> ReadOneFile(FileInfo file)
{
Stream _stream = new MemoryStream();
var fileStream = file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
{
try
{
using (var zip = new SevenZipExtractor(fileStream))
{
zip.ExtractFile(0, _stream);
_stream.Seek(0, SeekOrigin.Begin);
}
}
catch(Exception ex)
{
_stream = fileStream;
_stream.Seek(0, SeekOrigin.Begin);
}
}
return Serializer.Read2View(_stream);
}
示例15: ExtractFFmpeg
public static bool ExtractFFmpeg(string zipPath, string extractPath)
{
try
{
if (NativeMethods.Is64Bit())
{
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z-x64.dll"));
}
else
{
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z.dll"));
}
Helpers.CreateDirectoryIfNotExist(extractPath);
using (SevenZipExtractor zip = new SevenZipExtractor(zipPath))
{
Regex regex = new Regex(@"^ffmpeg-.+\\bin\\ffmpeg\.exe$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
foreach (ArchiveFileInfo item in zip.ArchiveFileData)
{
if (regex.IsMatch(item.FileName))
{
using (FileStream fs = new FileStream(extractPath, FileMode.Create, FileAccess.Write, FileShare.None))
{
zip.ExtractFile(item.Index, fs);
return true;
}
}
}
}
}
catch (Exception e)
{
DebugHelper.WriteException(e);
}
return false;
}