private void RetrieveData()
{
SevenZip.Compression.LZMA.Decoder coder = new SevenZip.Compression.LZMA.Decoder();
using (FileStream packFile = new FileStream("c:\\recieve.lzma", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (FileStream xmlFile = new FileStream("c:\\base.xml", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
coder.Code(packFile, xmlFile, -1, -1, null);
}
}
}
The error appears in LzmaDecoder.cs:
public void Init()
{
uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);
for (uint i = 0; i < numStates; i++)
m_Coders[i].Init(); //ERROR: Object reference not set to an instance of an object
}
Please, tell me what am I doing wrong??
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As I understand, in my previous code I haven't set Decoder properties. Now I've done it, but there is another error occur. Error appears in m_OutWindow.Create(blockSize) call with blockSize = 2278231838. Error text: 'Arithmetic operation resulted in an overflow'. What is wrong now? Sorry if I'm asking silly questions, but this decoding process is really hard to understand for me.
This is my current code:
using (FileStream inStream = new FileStream("c:\\recieve.lzma", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (FileStream outStream = new FileStream("c:\\base.xml", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
byte[] properties = new byte[5];
if (inStream.Read(properties, 0, 5) != 5)
throw (new Exception("input .lzma is too short"));
SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();
decoder.SetDecoderProperties(properties);
long outSize = 0;
for (int i = 0; i < 8; i++)
{
int v = inStream.ReadByte();
if (v < 0)
throw (new Exception("Can't Read 1"));
outSize |= ((long)(byte)v) << (8 * i);
}
long compressedSize = inStream.Length - inStream.Position;
decoder.Code(inStream, outStream, compressedSize, outSize, null);
}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is a code which generates a error:
private void RetrieveData()
{
SevenZip.Compression.LZMA.Decoder coder = new SevenZip.Compression.LZMA.Decoder();
using (FileStream packFile = new FileStream("c:\\recieve.lzma", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (FileStream xmlFile = new FileStream("c:\\base.xml", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
coder.Code(packFile, xmlFile, -1, -1, null);
}
}
}
The error appears in LzmaDecoder.cs:
public void Init()
{
uint numStates = (uint)1 << (m_NumPrevBits + m_NumPosBits);
for (uint i = 0; i < numStates; i++)
m_Coders[i].Init(); //ERROR: Object reference not set to an instance of an object
}
Please, tell me what am I doing wrong??
CS\7zip\Compress\LzmaAlone\LzmaAlone.cs
check the code after "else if (command == "d")"
As I understand, in my previous code I haven't set Decoder properties. Now I've done it, but there is another error occur. Error appears in m_OutWindow.Create(blockSize) call with blockSize = 2278231838. Error text: 'Arithmetic operation resulted in an overflow'. What is wrong now? Sorry if I'm asking silly questions, but this decoding process is really hard to understand for me.
This is my current code:
using (FileStream inStream = new FileStream("c:\\recieve.lzma", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (FileStream outStream = new FileStream("c:\\base.xml", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
byte[] properties = new byte[5];
if (inStream.Read(properties, 0, 5) != 5)
throw (new Exception("input .lzma is too short"));
SevenZip.Compression.LZMA.Decoder decoder = new SevenZip.Compression.LZMA.Decoder();
decoder.SetDecoderProperties(properties);
long outSize = 0;
for (int i = 0; i < 8; i++)
{
int v = inStream.ReadByte();
if (v < 0)
throw (new Exception("Can't Read 1"));
outSize |= ((long)(byte)v) << (8 * i);
}
long compressedSize = inStream.Length - inStream.Position;
decoder.Code(inStream, outStream, compressedSize, outSize, null);
}
}
Error occurs even if I'm trying to decode by lzma.exe.
Command: 'lzma.exe d recieve.lzma base.xml'
Error: 'SetDecoderProperties error'
Create .lzma file with lzma.exe:
lzma.exe e base.xml recieve.lzma