I want to create a compressed zip file and put inside it a single existing file.
I saw the help documents and I don't understand how can I do it.
I would really appreciate your help!
How to put a file inside a zip file Topic is solved
-
- wxWorld Domination!
- Posts: 1059
- Joined: Sun Dec 30, 2007 6:40 pm
- Location: Canada
Hi,
Check the reference code here: http://docs.wxwidgets.org/stable/wx_wxa ... xarccreate
Hope that helps,
Jim
Check the reference code here: http://docs.wxwidgets.org/stable/wx_wxa ... xarccreate
Hope that helps,
Jim
OS: Vista SP1, wxWidgets 2.8.7.
-
- Experienced Solver
- Posts: 72
- Joined: Fri Feb 20, 2009 7:13 pm
- Location: $(#wx)\src
To add to that, there are TONS and TONS and TONS of libraries that you can choose from to do this. One of the more popular open source libraries is known as LZMA SDK. 7 Zip uses this compression library and I believe it has a few functions that could help you out. But they're are a lot more than that, just look around. wxWidgets built in widget works too.
But if the file I want to put inside the zip archive isn't a text file does it works?JimFairway wrote:Hi,
Check the reference code here: http://docs.wxwidgets.org/stable/wx_wxa ... xarccreate
Hope that helps,
Jim
-
- Experienced Solver
- Posts: 72
- Joined: Fri Feb 20, 2009 7:13 pm
- Location: $(#wx)\src
-
- Super wx Problem Solver
- Posts: 323
- Joined: Sun Jun 08, 2008 11:59 am
- Location: Bordeaux, France
Off course it works ! Zip compression can match every file formats ! Here is an example but try to search a bit in the wxWidgets documentation :
I made this simple piece of code but I did no try to build it. Hope it will help you. Also have a look to the inheritence diagram on the stream management (wxDataOutputStream accepts a wxDataStream object reference). According to this diagram, you can guess all objects that derive from wxDataStream and then use them :
http://docs.wxwidgets.org/trunk/classwx ... tream.html
(I think this diagram very useful...).
Good luck.
Code: Select all
wxFFileOutputStream loc_o_file( _S( par_o_file ) );
wxZipOutputStream loc_o_zip( loc_o_file );
wxDataOutputStream loc_o_data( loc_o_zip );
// Create a new entry (ie a new file) into your archive
loc_o_zip.PutNextEntry( wxT("test.bin") );
// Write your bin data here
loc_o_data << YOUR_BINARY_DATA_HERE ;
http://docs.wxwidgets.org/trunk/classwx ... tream.html
(I think this diagram very useful...).
Good luck.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3
I tried this, but the compressed file isn't made equal as the input file:Muetdhiver wrote:Off course it works ! Zip compression can match every file formats ! Here is an example but try to search a bit in the wxWidgets documentation :
I made this simple piece of code but I did no try to build it. Hope it will help you. Also have a look to the inheritence diagram on the stream management (wxDataOutputStream accepts a wxDataStream object reference). According to this diagram, you can guess all objects that derive from wxDataStream and then use them :Code: Select all
wxFFileOutputStream loc_o_file( _S( par_o_file ) ); wxZipOutputStream loc_o_zip( loc_o_file ); wxDataOutputStream loc_o_data( loc_o_zip ); // Create a new entry (ie a new file) into your archive loc_o_zip.PutNextEntry( wxT("test.bin") ); // Write your bin data here loc_o_data << YOUR_BINARY_DATA_HERE ;
http://docs.wxwidgets.org/trunk/classwx ... tream.html
(I think this diagram very useful...).
Good luck.
Code: Select all
void MainWindow::BufferedCopy(wxTextInputStream& inStream, wxTextOutputStream& outStream)
{
wxString str;
for(;;) {
str = inStream.ReadLine();
if(str == wxEmptyString)
break;
outStream << str;
}
}
void MainWindow::exportCollection(const wxString& from, const wxString& to)
{
wxFFileInputStream in(from);
wxTextInputStream inStream(in);
wxFFileOutputStream out(to);
wxZipOutputStream zip(out);
wxTextOutputStream outStream(zip);
zip.PutNextEntry(wxT("collection.col"));
BufferedCopy(inStream, outStream);
}
-
- Experienced Solver
- Posts: 86
- Joined: Wed Apr 18, 2007 6:10 am
- Location: Shanghai China
I compress the files into "a images.zip", for reference only.
Code: Select all
bool CreateImageZip(const wxString &ressoureDir, const wxString &destPath)
{
wxString sep(wxFileName::GetPathSeparator());
wxArrayString files;
wxDir::GetAllFiles(ressoureDir,&files);//the dir contented all the files need to compress.
wxFFileOutputStream fileout(destPath+_T("images.zip"));
wxZipOutputStream zipout (fileout);
wxFFileInputStream *in = NULL;
wxZipEntry *entry=NULL;
wxFileName *zipname = NULL;
for (size_t i = 0;i != files.GetCount(); ++i)
{
if (in!=NULL)
{
delete in;
in = NULL;
}
if (zipname!=NULL)
{
delete zipname;
zipname = NULL;
}
in = new wxFFileInputStream(files[i]);
zipname = new wxFileName (files[i]);
if(zipname->MakeRelativeTo(ressoureDir))
{
entry = new wxZipEntry(wxT("images/")+zipname->GetFullPath());
zipout.PutNextEntry(entry);
zipout.Write(*(in));
}
else
{
return false;
}
}
zipout.CloseEntry();
zipout.Close();
fileout.Close();
if (in!=NULL)
{
delete in;
in = NULL;
}
if (zipname!=NULL)
{
delete zipname;
zipname = NULL;
}
return true;
}