Determine size of files in zip? - ios

To keep total size of my app down, I would like to distribute some very large databases as ZIP files, then unpack them as needed. Is there an easy way to determine the size of a file in a ZIP so I know in advance if there is space on the device to even try to unzip one of them?
The ZIP file would contain only one file. Yes, I could measure the size in advance and hardcode it, but that's error prone, as I update the databases on a regular basis.
Best regards,
Anders

There are a few 3rd party Objective-C libraries for working with ZIP files. These would allow you to interrogate the contents of a zip file without needing to unzip them first.
Check out ZipKit or Objective-Zip.

You can also use zipzap like this:
NSUInteger wantedFileSize = NSNotFound;
ZZArchive* archive = [ZZArchive archiveWithURL:zipFileURL error:nil];
for (ZZArchiveEntry entry in archive.entries)
if ([entry.fileName isEqualToString:wantedFileName])
{
wantedFileSize = entry.uncompressedSize;
break;
}
This will be fast since it only scans the last blocks of the zip file for the uncompressed size of the entry you want, and doesn't do any decompression.

Related

Generate CRC32 checksum of file swift

I have a .zip file inside the project and I am transferring it to the external ESP32 via Bluetooth. But I need to send the CRC-32 checksum at the end of the sending file. I don't have any idea how to generate it.
Can anyone help me with how to do it in the right way?
Thanks in advance.
So, I have found one amazing framework called CryptoSwift. This made my day. Here is how
Get file Data from the file path.
I have a function which returns Data from file name and type.
And CryptoSwift has the extension of Data which converts the crc32 by calling simply .crc32()
and than call crc32()
let crcChecksum = Utils.sharedInstance.getFileData(forResource: "firmware", withExtension: "bin").crc32()
For mote detail.
https://github.com/krzyzanowskim/CryptoSwift

how to redirect the trace window output to a file in CANoe

i would like to get all the data present in the trace window to my text file, even log recording can help but it can't display date and time in that file, so i've a plan to copy entire trace window to file.
i've tried to do ctrl+a and paste in notepad, but it is just copying some sort of area only not all.
i would like to know is there any chance to redirect how trace window is printing like that i can see in text file, or at least is there any way to copy entire file and paste in text file.
The trace windows just display the data, you configure it in the Measurement Setup.
But be aware that this will be only a part of the data anyway. There is a buffer where CANoe stores the data for the Trace window. You can configure the type of this buffer (memory or hard disk) and its size. Go to Options -> Measurement -> Data History to change your settings.
You can also configure the size of the visible data range there. But even with a very long range and a large 200 GB buffer, there might be a possibility that some data will not be available, because the Trace works as a ring buffer deleting the old data on overflow.
If you need the complete data, you should enable the Logging in the Measurement setup. Yes, the data files will be not human-readable. You will then need to open them in the Offline Mode in CANoe to analyze them. The timestamps will be of course logged, so you can easily use them for your analysis.
You could pretty-print it to the write window using CAPL:
on message *
{
int i;
write("[%07.3f] %03X", this.time / 100000.0, this.id);
for (i = 0; i < this.dlc; i++)
writeEx(0, 0, " %02X", this.byte(i));
}
And then export it to a file.
Or you write it directly to a file.
Hi I would suggest logging the necessary data into a CSV and then analyzing using Excel. You can make use of the File Access CAPL functions like openFileWrite for the same

Does NSFileWrapper load everything into memory?

Lets say I have an NSFileWrapper directory. This directory is made up of several levels of directories and files. Some of the files are large. Are all these files loaded into memory, or are they lazily loaded?
If they are loaded into memory, are there any alternatives to NSFileWrapper with similar functionality that won't load files into memory? Something I can hook into UIDocument?
This is for a document based application, which uses UIDocument's that are synced with iCloud. A document can have images and videos embedded inside it. Each image/video has a preview image (thumbnail) that is shown in an HTML document. The full size images or videos shouldn't be loaded into memory, but rather loaded on demand.
I also need a way to add a resource without loading it into memory. Something like "initWithAsset:(ALAsset *)" would be ideal.
I've made an app a while ago that generates a video. This video was then saved to a specific file format using a UIDocument subclass.
The only way to make the app not run out of memory while executing contentsForType:error: was to output the video to a file in the tmp dir and init the filewrapper with the url to the video with NSFileWrapperReadingWithoutMapping-option to prevent it from loading the video to memory and just copy in the file.
- (id)contentsForType:(NSString *)typeName error:(NSError **)outError {
if (self.fileWrapper == nil) {
self.fileWrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers:nil];
}
if (self.videoURL != nil) {
NSError *fileReadError;
NSFileWrapper *videoFileWrapper = [[NSFileWrapper alloc] initWithURL:self.videoURL options:NSFileWrapperReadingWithoutMapping error:&fileReadError];
if(fileReadError){
NSLog(#"File read error: %#", [fileReadError localizedDescription]);
}else {
[videoFileWrapper setPreferredFilename:#"video.mov"];
[self.fileWrapper addFileWrapper:videoFileWrapper];
}
}
//...
}
It's not totally clear from the documentation, but I'm 99% positive that NSFileWrapper will memory-map everything. The main use case for NSFileWrapper is to embed files inside documents, where you'd presumably need access to said file at all times.
What are you trying to use the file wrapper for? I assume if you're mapping an entire directory it's not necessarily to embed media inside a document, but perhaps I'm mistaken. If you maybe talk a bit more about your use case, as that will influence what alternatives you might go for.

PHP upload not working due to size limitation

my php.ini values
upload_max_size = 14000M
post_max_size = 14000M
if i increase value more than 14000M, $_POST can't be accessed and using that value i can upload a file of 1.5GB only and can't upload a file of 2.14GB.
Here i have three questions
What should i do so $_POST array also keep in working and i can also
upload a file of 2.14 GB.
Why $_POST is not working when i exceed
value more than 14000M
14000M should mean 14GB, isn't so? if so
then why i can't upload file of 2.14GB
i found answer to my question after 2 days work.
This is a bug in PHP which allow us to put *_max_size = 14000M and don't allow us to upload a file of 14000MB.
Reference https://bugs.php.net/bug.php?id=35578
We can't upload file for more than 2047MB, so following values are meaning less
upload_max_size = 14000M
post_max_size = 14000M
and should be converted to its maximum value like
upload_max_size = 2047M
post_max_size = 2047M
So now you can upload about 1.99GB File
THere is no only upload_max_size and post_max_size that affect on file upload. Check this link
The most important is memory_limit. when you tring to upload big file, php run out memory
I have had luck using G (Gigs) in my php.ini file:
upload_max_size = 3G
post_max_size = 3G
Not sure if this will help with the $_POST issue.
There are much more limitations and pitfalls you have to check for, see oficial PHP documentation: http://www.php.net/manual/en/features.file-upload.common-pitfalls.php
Anyway, note that the 2G is also a limit of signed 32bit integer! So this problem might rise from some other limits unrelated to upload itself. Also, what is the maximum file size on the server filesystem? 2G is a limit on some systems.

How to Reduce AIR app file size?

I've uploaded an AIR-built .ipa file to Apple. From Apple: "The app binary listed below was 8 MB when you submitted it, but will be 20 MB once processed for the App Store"
So I'm trying to trim it. I've gotten rid of all unused .as classes and all unused assets. Does anyone have any clever way of reducing file size further? One way I thought of is this:
If in class A I have:
[Embed(source="assets/newButtons/purple/purpleHomeSmall.png")]
and then I re-embed it in class B with the same code, does that mean it is embedded twice with twice the file size? If so, how would I embed it in one class but have access to it in other classes?
Edit: I've discovered that if you have assets in your project that you don't use, the compiler STILL ADDS them. So you have to get rid of them before making a release build.
Instead of embedding the source why not just load it from URI at runtime?
Create an abstract bitmap class that builds a bitmap from the URI and places it on stage.
This way you can ensure the bitmap is only stored once and is loaded lazily.
Update
you can add a folder in the air for iOS settings dialog.
Place the images you want and then:
var imageLoader:Loader = new Loader();
var theURL:String = "string to your uri can be local or web";
var imageRequest = new URLRequest(theURL);
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
imageLoader.load(imageRequest);
function onComplete(evt:Event)
{
addChild(imageLoader.content);
}
One option i have used is to compile the ipa with only the most necessary assets and then when the user first initializes the app have it download and store further assets in the application storage (this could be done with a single zip-file and the FZip class: http://codeazur.com.br/lab/fzip/)
This way the app only has to download the assets once (on first run) and they are immediately available in the future from the local system.
Instead of embedding images in each source file, what I do is create a class in the default package, where I place all my images as static public variables. Something like this:
package {
public class Icons{
[Embed(source="assets/icon1.png")] [Bindable] static public var icon1:Class;
}
}
Whenever I need the icon, I just use Icons.icon1.
You cannot ! Your app will be more than 20Mb and its like that. Because the need of Adobe AIR runtime, embedded in your IPA.
So its useless to try to optimize your code, asset .... should chase adobe for this job !
My application: prestadget is 800Ko as APK (w/o AIR runtime) but 21Mo as IPA ;-( same code

Resources