Added support for LZIP compressed files (.lz).

This commit is contained in:
2017-06-07 18:36:06 +01:00
parent 149949b29f
commit 9fe8399d6a
3 changed files with 167 additions and 4 deletions

View File

@@ -48,6 +48,7 @@
<Compile Include="MacBinary.cs" />
<Compile Include="BZip2.cs" />
<Compile Include="PCExchange.cs" />
<Compile Include="LZip.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\LICENSE.LGPL">

View File

@@ -5,11 +5,11 @@
// Filename : LZip.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Component
// Component : Filters.
//
// --[ Description ] ----------------------------------------------------------
//
// Description
// Allow to open files that are compressed using lzip.
//
// --[ License ] --------------------------------------------------------------
//
@@ -29,13 +29,174 @@
// ----------------------------------------------------------------------------
// Copyright © 2011-2017 Natalia Portillo
// ****************************************************************************/
using System;
using System.IO;
using DiscImageChef.Console;
using SharpCompress.Compressors;
using SharpCompress.Compressors.LZMA;
namespace DiscImageChef.Filters
{
public class LZip
public class LZip : Filter
{
Stream dataStream;
string basePath;
DateTime lastWriteTime;
DateTime creationTime;
bool opened;
long decompressedSize;
Stream innerStream;
public LZip()
{
Name = "LZip";
UUID = new Guid("FCCFB0C3-32EF-40D8-9714-2333F6AC72A9");
}
public override void Close()
{
if(dataStream != null)
dataStream.Close();
dataStream = null;
basePath = null;
opened = false;
}
public override string GetBasePath()
{
return basePath;
}
public override Stream GetDataForkStream()
{
return innerStream;
}
public override string GetPath()
{
return basePath;
}
public override Stream GetResourceForkStream()
{
return null;
}
public override bool HasResourceFork()
{
return false;
}
public override bool Identify(byte[] buffer)
{
return buffer[0] == 0x4C && buffer[1] == 0x5A && buffer[2] == 0x49 && buffer[3] == 0x50 && buffer[4] == 0x01;
}
public override bool Identify(Stream stream)
{
byte[] buffer = new byte[5];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(buffer, 0, 5);
stream.Seek(0, SeekOrigin.Begin);
return buffer[0] == 0x4C && buffer[1] == 0x5A && buffer[2] == 0x49 && buffer[3] == 0x50 && buffer[4] == 0x01;
}
public override bool Identify(string path)
{
if(File.Exists(path))
{
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[5];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(buffer, 0, 5);
stream.Seek(0, SeekOrigin.Begin);
return buffer[0] == 0x4C && buffer[1] == 0x5A && buffer[2] == 0x49 && buffer[3] == 0x50 && buffer[4] == 0x01;
}
return false;
}
public override void Open(byte[] buffer)
{
dataStream = new MemoryStream(buffer);
basePath = null;
creationTime = DateTime.UtcNow;
lastWriteTime = creationTime;
innerStream = new ForcedSeekStream<LZipStream>(dataStream, CompressionMode.Decompress, false);
decompressedSize = innerStream.Length;
opened = true;
}
public override void Open(Stream stream)
{
dataStream = stream;
basePath = null;
creationTime = DateTime.UtcNow;
lastWriteTime = creationTime;
innerStream = new ForcedSeekStream<LZipStream>(dataStream, CompressionMode.Decompress, false);
decompressedSize = innerStream.Length;
opened = true;
}
public override void Open(string path)
{
dataStream = new FileStream(path, FileMode.Open, FileAccess.Read);
basePath = Path.GetFullPath(path);
DateTime start = DateTime.UtcNow;
DateTime end = DateTime.UtcNow;
FileInfo fi = new FileInfo(path);
creationTime = fi.CreationTimeUtc;
lastWriteTime = fi.LastWriteTimeUtc;
innerStream = new ForcedSeekStream<LZipStream>(dataStream, CompressionMode.Decompress, false);
decompressedSize = innerStream.Length;
opened = true;
}
public override DateTime GetCreationTime()
{
return creationTime;
}
public override long GetDataForkLength()
{
return decompressedSize;
}
public override DateTime GetLastWriteTime()
{
return lastWriteTime;
}
public override long GetLength()
{
return decompressedSize;
}
public override long GetResourceForkLength()
{
return 0;
}
public override string GetFilename()
{
return basePath != null ? Path.GetFileName(basePath) : null;
}
public override string GetParentFolder()
{
return Path.GetDirectoryName(basePath);
}
public override bool IsOpened()
{
return opened;
}
}
}
}

View File

@@ -170,6 +170,7 @@ Supported filters
* AppleSingle
* BZip2
* GZip
* LZip
* MacBinary I, II, III
Changelog