I'm developing a BlackBerry application in which I need to unpack a zip file compressed with PKZIP. The package could have one file in it, or it could have 10; it will vary in each case. I know that the BlackBerry API has native support for GZip and Zlib, although I'm pretty sure that these methods aren't going to be helpful in my case. It doesn't look as if I can extract the individual files using these calls.
I've tried JZlib (http://www.jcraft.com/jzlib/), which compiled fine, but again it doesn't look as if the methods contained therein are going to allow me to pull the individual files.
It appears as if this is possible, as there's an application called Ziplorer (http://www.s4bb.com/software/ziplorer/) that claims to do perform this exact procedure. How they're doing it, however, escapes me.
So here I am after hours of Googling. I'm welcoming any insight into my problem with open arms.
"zip" algorithms are typically offshoots of the Lempel-Ziv-Welch algorithm. They are a fairly efficient stream compression algorithms, but because of how they function, you can't start to decompress at random points in the file, you have to start from the start.
Any product that claims to be able to decompress one file from a zip still has to decompress everything before it in the zip file in order to know how to decrypt the given file, or even, for that matter, where the file is in the archive.
If you can tolerate GPL code in your application, then this library http://jazzme.sourceforge.net/ that might work. However the project (and its parent project http://sourceforge.net/projects/jazzlib/) don't look like they're being developed.
Related
I've been trying to load a library into lua file. Sparing the details, as they are not really important, I have tried this many ways.
The final way, and the one I believe to be correct although I still can't get it to work, is to use "package.loadlib". See code:
ed = package.loadlib("Encode_Decode.lua", "luaopen_ed")
print(ed)
But when I run the program I get this error:
Encode_Decode.lua is either not designed to run on Windows or it
contains an error. Try installing the program again using the original
installation media or contact your system administrator or the
software vendor for support.
I know the program runs because I used it internally to test it's encoding and decoding abilities and it worked fine. I'd really prefer not moving the contents of the library over as my main lua file is crowded as it is. I will if I have to though.
Yes it is in the main folder. I've also tried changing the extension of the library file into a .dll, with the same error.
What am I doing wrong?
I apologize in advance if this is a duplicate, I did my best to research this problem as thoroughly as I could. But to be honest it's almost 3 AM and I've been searching for almost an hour.
Stupid beginner mistake, used the wrong syntax.
require("Encode_Decode")
print(dec("bnVs")) --returns "nul"
package.loadlib is used for loading shared libraries; i.e. .dll or .so files. You're passing a .lua file to it, so Windows attempts to load it as a .dll and fails when it can't.
To load Lua source code, you can use dofile. Alternatively, you can use require, which is a bit more complex, but handles loading modules only once and works with both Lua and C modules.
I have a path library which has a zip function in it, and while writing the unit test, I tried to find the best way to verify that the zip function works correctly.
Can someone please show me the best way to verify that the zip function works correctly ?
The few ways I can think of are:
Comparing the md5 of the resultant zip file against a sample zip file
Listing out the contents of the zip file and ensuring the content are correct
However, both ways seems a little long winded and I am guessing not exactly idiomatic Elixir. Can someone please show me a better way ?
I would create a directory of test files to zip up in your unit test, zip it up using a trusted utility and get the resulting md5. Then for your unit test, perform the zip function, take the md5, and compare with your verified md5.
If I am correct, there are some parameters that can affect the result of zip processing (like block size). So, unless your purpose is to check exhaustively that your zip process reproduces all or a subset of the zip features, I find more interesting to validate that various files from your system (or/and some random files) can be compresses with your function, and uncompressed outside using different unzip tools, and finally compare that the files are identical to the original. (of course it takes more time, but it can be easily automated).
Concerning the usage of MD5 rather than file comparison, I think that on one hand file comparison is easy to write and in the other hand you need to read the whole file to calculate the MD5, so I don't think it is worth to use this trick to accelerate the comparison - (especially if files are different :o).
I have a huge text file in my application (version 1.0).
Lets assume that a new version (2.0) of this file was just released.
Most of the file remained the same but the new (2.0) version has a few modifications (some lines removed, others added).
I now wish to update the file (1.0) to the new version (2.0), but do not wish to download the whole file again.
I would love to just patch the file with the changes of the new file, thus saving bandwith from downloading the WHOLE new file from my server.
(Similar to the way versioning systems like git or svn act)
How can I do this programmatically? Are there any iOS libraries available?
Thank you
You need to implement some kind of Binary delta compression such as zdelta, or Remote Differential Compression such as the one in rsync.
Personally I'm not aware of such algorithm implemented specifically for iOS, but I'm sure it's possible to find one that is implemented in C/C++ which can be seamlessly used in the iOS environment.
Edit: I also recommend you to read this.
It's actually a big problem... if your API let you ask the data of a file in a specific range, you can just a ask the data range that you need to replace, and seek the file at the range and overwrite the specific data... this mean that you have to take trace about the changes every time you update the files... and your app update has to know the ranges to request... this is not a solution... I hope will be a start point to implement your own solution
to try to get partial conent in a range you need to add to your request header something like this:
Range: bytes=0-999
I think, you can do this by yourself without third party libraries. To achieve this, all you need is 1)Piece of code which will generate the metadata for joining versions of your file (offsets, lengths, and pointers to the data to be changed in older version); 2)piece of code which will do the hard work: read meta and put the parts on right places. Several days of struggling with offsets, and you are done ;) Good luck!
I have an nascent iPad application, which stores "documents" internally on the device in the file system as a series of distinct files in a folder.
I'd like to try incorporating an import/export function through iTunes, using the features for OS 3.2 for this. I want to put all the document pieces that I keep internally into one container file for export.
So, smart folks of Stack Overflow: What's the simplest solution that will put a file hierarchy (or could be flat list in a pinch) into one file? There will not in theory need to be manipulation of the "archive"/container outside the app-- so random access isn't super important here, although it would be a bonus of course.
A tar file type thing springs to mind immediately. Roll my own? Any other thoughts or gotchas? (And if anyone can point me to code that reads/writes from a tar file, I'm all ears.)
Thanks!
Update: Made community wiki, since there's no single right answer here.
Try libarchive which is a friendly licensed, BSD derived (easier for iPhone OS) library for handling archive files.
The RIM compiler performs extra optimization and compression on the resulting ".jar" while building the final .cod file, but there are things that can be done by the developer to significantly reduce the final .cod file size.
One such thing would be to run PNGCrush, OptiPNG, or a similar tool to reduce the size of the included .png files. In an application with a large number of image files (such as an app featuring a custom UI), this can yield a significant reduction in the final .cod file size.
How can I optimize the final .cod file for size? Something to be done in the .java code itself? Something to be done in the project structure? Something to be done to the files or resources?
Good question!
Compression (GZip, ZLib) may be useful when installing large bin/txt/xml files
And that's what they say in RIM:
Setting appropriate access
Avoid creating interfaces
Use static inner classes
Avoid unnecessary field initialization
Import individual classes
Also, interesting facts:
All images was PNG format. I want to
know why : compile with JDE 4.5 -->
900k, compile JDE 4.2, 2.6.1, 4.7 -->
1800k. What is difference ? Thanks !
Seems that JDE 4.5 uses more optimization techniques than older JDE
versions.
Check the image below, it produced by PngOut from 55 K png image. It's size is 3427 bytes
I think you most certainly want to consider a shrinker (and optimizer/obfusticator) like ProGuard (http://sourceforge.net/projects/proguard/). This can shrink your Java code by collapsing full class names into shortened versions, removing unused code, etc. Along the way it can improve the efficiency of the code. It's great. The only hard part is modifying your build to optimize the generated class files before the RIM build stuff gets its hands on it to make a .cod.
A good approach is to GZIP all resources and then use net.rim.device.api.compress.GZIPInputStream class to load compressed files. That way you don't have to implement decompress code by yourself.
Also you can use pngout for optimizing image resources.
Make sure that you use PNG-8 instead of PNG-24 when possible. Try to minimize number of colors in palette. After this, use PngOut.
As for ProGuard, I have problems on old BB devices when using optimize feachure of Progruard ("-dontoptimize" switch) - so use it carefully, although it is a great tool.