Search code examples
compression7ziplzma

7Zip CLI Compress file with LZMA


I try to compress a file in the console with LZMA.

7z a -t7z output input
or
7z a -t7z -m0=lzma output input

However, I cannot open it on the client.

How can compress a file as an LZMA archive in the console?

It is possible the problem to be that the above commands add a file in an archive. However, I want to compress data in a data file without file structure.

Is there an option to compress a data file to a compressed data file with LZMA?

Edit

I see downvotes, which means the question is "not correct" in some way.

So I'll try to explain what I want to achieve.

I compress data serverside and use them on a client application. I successfully do it in Node.js like that:

const lzma = require('lzma');

lzma.compress(inputBuffer, 1, callback);

function callback(data, err) {
    writefile(outputPath, Buffer.from(data));
}

However, it is very slow. So I want to call 7Zip for the compression.

My .NET server also compresses it in a similar way.

byte[] barData;
using (var barStream = dukasDataHelper.SerializeLightBars(lightBars.ToArray()))
using (var zippedStream = zipLzma.Zip(barStream))
{
    barData = zippedStream.ToArray();
}

My problem is that I cannot set the correct options in CLI in order to be able to read the file in the client.

My client code C# is:

using (var blobStream = new MemoryStream(blobBytes))
using (var barStream = new ZipLzma().Unzip(blobStream))
{
    SaveDataSet(barStream, localPath);
}

I have this error message when compress via CLI:

  $exception {"Data Error"}
  Data: {System.Collections.ListDictionaryInternal}
  at SevenZipLzma.LZMA.Decoder.Code(Stream inStream, Stream outStream, Int64 
  inSize, Int64 outSize, ICodeProgress progress)
  at SevenZipLzma.ZipLzma.Unzip(Stream stream)

Since the code works as I compress with Node.js and doesn't work when compressing via CLI, it means something is wrong.


Solution

  • 7zip makes an archive of files and directories, whereas LZMA generates a single stream of compressed data. They are not the same format. LZMA can be used inside a 7zip archive to compress an entry (or LZMA2 or Deflate or several other compression methods).

    You can try the xz command to generate LZMA streams with xz --format=lzma.