I want to set password for zip files using minizip.I didn't find an documentation regarding this.I know we can encrypt all the zipped file.
A complete example using C code is provided in the /contrib/minizip directory: minizip.c for the compression, miniunzip.c for the decompression.
As said in the previous comment zipOpenNewFileInZip3 is for compression with password.
For decompression you have to open the zipped file(s) with unzOpenCurrentFilePassword.
Googling:
err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi,
NULL,0,NULL,0,NULL /* comment*/,
(opt_compress_level != 0) ? Z_DEFLATED : 0,
opt_compress_level,0,
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
password,crcFile, zip64);
Taken from here.
If you use from command line:
minizip [-p password]
Related
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.
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.
I'm looking in "PhysicsFS" documentation and search for way to archive and compress data but can't find.Is it possible and if it is how i can do that
PhysicsFS zip support
PhysicsFS has support for reading files from a zip file mounted at an arbitrary point in the "virtual filesystem" that it provide. This effectively provide decompression from a ZIP archive.
However, PhysicsFS has no support to add or modify the content of a ZIP archive. It only permit to write uncompressed files in what is called "the write directory" in its documentation.
So, to summarize: PhysicsFS only support reading from ZIP archives, not writing to it.
For the compression you are on your own: just zip all the written files using an external compressor if you need so.
PhysicsFS usage
There is a small tutorial for PhysicsFS here.
It is very simple to use:
// initialize the lib
PHYSFS_init(NULL);
// "mount" a zip file in the root directory
PHYSFS_AddToSearchPath("myzip.zip", 1);
// set a directory for writing
PHYSFS_setWriteDir(const char *newDir);
// open a file for reading
PHYSFS_file* myfile = PHYSFS_openRead("myfile.txt");
// open a file for writing
PHYSFS_file* myfile = PHYSFS_openWrite("output_file.bin");
// get a file size
PHYSFS_sint64 file_size = PHYSFS_fileLength(myfile);
// read data from a file (decompress only if path is inside a zip mount point)
char* myBuf = new char[file_size];
int length_readed = PHYSFS_read(myfile, myBuf, 1, file_size);
// write data to a file (uncompressed)
char* myBuf = new char[new_file_size];
//...fill myBuf...
int length_writed = PHYSFS_write(myfile, myBuf, 1, new_file_size);
// close a file
PHYSFS_close(myfile);
// deinitialize the lib
PHYSFS_deinit();
Is it possible that you meant "PhysFS".
That is a library to read files from a zipfile. Basically like the Quake engine does.
I need to be able to unzip some AES (WinZip) encrypted zip files from within some C/C++ code on Windows. Has anybody got a way to do this? I'm hoping for either some appropriate code or a DLL I can use (with an example usage). So far my searches have proved fruitless.
The commonly prescribed InfoZip libraries do not support AES encryption.
The best solution I have at the moment is calling the 7z.exe command line program from my program, but considering I'll be unzipping 100 files or so, this is less than ideal.
Here is the minizip zlib contribution with AES support for both encryption and decryption.
https://github.com/nmoinvaz/minizip
DotNetZip can do it. If you're not averse to using Managed C++.
From the DotNetZip documentation, this is the code to create an AES Encrypted zip file. (The code to extract is similar).
#include "stdafx.h"
using namespace System;
using namespace Ionic::Zip;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
ZipFile ^ zip;
try
{
zip = gcnew ZipFile();
zip->Password = "Harbinger";
zip->Encryption = EncryptionAlgorithm::WinZipAes128;
zip->AddEntry("Readme.txt", "This is the content for the Readme.txt entry.");
zip->Save("test.zip");
}
finally
{
zip->~ZipFile();
}
Console::WriteLine(L"Press <ENTER> to quit.");
Console::ReadLine();
return 0;
}
Also - I wrote DotNetZip so I have a certain amount of favoritism toward it! But I don't see what's wrong with exec'ing 7z.exe 100 times? Are you concerned about performance?
http://www.artpol-software.com/ZipArchive/ is the best choice.
I'm trying to install WMA DRM licenses files silently so that users would not have to play each song and acknowledge for each license.
I figured out that I need to do something like this :
HRESULT res = CoCreateInstance(__uuidof(RMGetLicense),NULL,CLSCTX_ALL,__uuidof(IRMGetLicense ),(void**) &pLicense );
res = pLicense->GetLicenseFromURL(NULL, bstrURL);
The bstrURL is expected to contain a keyID as a parameter, which allow to retrieve the file matching with the music file. I can't find how to get this keyID back from the WMA file.
I may get the problem wrongly though. Am I in the good way ?
You have to pass header object as a first parameter. More information is in MSDN
I'm writing a browser plugin, similiar to Flash and Java in that it starts downloading a file (.jar or .swf) as soon as it gets displayed. Java waits (I believe) until the entire jar files is loaded, but Flash does not. I want the same ability, but with a compressed archive file. I would like to access files in the archive as soon as the bytes necessary for their decompression are downloaded.
For example I'm downloading the archive into a memory buffer, and as soon as the first file is possible to decompress, I want to be able to decompress it (also to a memory buffer).
Are there any formats/libraries that support this?
EDIT: If possible, I'd prefer a single file format instead of separate ones for compression and archiving, like gz/bzip2 and tar.
There are 2 issues here
How to write the code.
What format to use.
On the file format, You can't use the .ZIP format because .ZIP puts the table of contents at the end of the file. That means you'd have to download the entire file before you can know what's in it. Zip has headers you can scan for but those headers are not the official list of what's in the file.
Zip explicitly puts the table of contents at the end because it allows fast adding a files.
Assume you have a zip file with contains files 'a', 'b', and 'c'. You want to update 'c'. It's perfectly valid in zip to read the table of contents, append the new c, write a new table of contents pointing to the new 'c' but the old 'c' is still in the file. If you scan for headers you'll end up seeing the old 'c' since it's still in the file.
This feature of appending was an explicit design goal of zip. It comes from the 1980s when a zip could span multiple floppy discs. If you needed to add a file it would suck to have to read all N discs just to re-write the entire zip file. So instead the format just lets you append updated files to the end which means it only needs the last disc. It just reads the old TOC, appends the new files, writes a new TOC.
Gzipped tar files don't have this problem. Tar files are stored header, file, header file, and the compression is on top of that so it's possible to decompress as the file it's downloaded and use the files as they become available. You can create gzipped tar files easily in windows using winrar (commercial) or 7-zip (free) and on linux, osx and cygwin use the tar command.
On the code to write,
O3D does this and is open source so you can look at the code
http://o3d.googlecode.com
The decompression code is in o3d/import/cross/...
It targets the NPAPI using some glue which can be found in o3d/plugin/cross
Check out the boost::zlib filters. They make using zlib a snap.
Here's the sample from the boost docs that will decompress a file and write it to the console:
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
int main()
{
using namespace std;
ifstream file("hello.z", ios_base::in | ios_base::binary);
filtering_streambuf<input> in;
in.push(zlib_decompressor());
in.push(file);
boost::iostreams::copy(in, cout);
}
Sure, zlib for example uses z_stream for incremental compression and decompression via functions inflateInit, inflate, deflateInit, deflate. libzip2 has similar abilities.
For incremental extraction from the archive (as it gets deflated), look e.g. to the good old tar format.