It is currently Wed Apr 26, 2017 8:11 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject: Re: Zip commands
Unread postPosted: Tue Jun 28, 2016 1:42 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5485
Location: Paris, France
Yes, you guessed right Gika: no need for a "Zip.create", just use Zip.open w, fid, "myfile.zip". If "myfile.zip" doesn't exist, it will be created (by command Zip.open, not command Zip.write).

Zip.* commands have been designed to be as close as their BASIC! counterparts Test.* and Byte.* commands.

And same as Text.* and Byte.* commands, the Zip.* commands are thin layers around the native Android commands (that's the spirit of BASIC!)

I'll provide some macro UDF (user-defined functions) to unzip a whole archive to a path, and reverse, to zip a whole folder into a zip.
You can then tune them to remove a specific file and create a new zip with one of the files deleted in it.

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Zip commands
Unread postPosted: Tue Jun 28, 2016 1:49 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5485
Location: Paris, France
Ok, after improving performance on Zip.read, I have reached a limit.

I gained 130 ms to unzip a 5 KB file. So now it takes ~390 ms instead of 520 ms. But it seems I can't optimize further.

I used this StackOverflow as source for optimizing: basically I am using BufferedIn[/Out]putStreams to accelerate the buffering of data.
The initial 520 ms time was not a bad score considering people were facing minutes on a single file in the StackOverflow (with no buffer at all, just a Byte array)...

I'll post my final commands to GitHub tonight if I can, for them to be in the next version of BASIC!

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Zip commands
Unread postPosted: Tue Jun 28, 2016 7:16 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5485
Location: Paris, France
Gikam, I uploaded to Paul's FTP the macro functions I promised:
http://laughton.com/basic/programs/utilities/mougino/

Sorry, I know sometimes it is not accessible in Romania, but I hope you can use a proxy and get them.

For what you wanted (alter a zip file), you'll need "zip_utils.bas" (of course) but also "file_utils.bas" and "str_utils.bas" (because zip_utils relies on some functions in file_utils, which itself relies on some other functions in str_utils).

To unzip a full folder-tree + files to a directory, write:
Code:
include "zip_utils.bas"
UnzipTo("bootstrap.zip", "test_bootstrap/")

Then you can delete some files in the test_bootstrap/ folder, for this you can rely on functions in "file_utils.bas", for example:
Code:
include "zip_utils.bas"
list.create s, files
RecursiveDir("test_bootstrap/", files)
list.get files, 10, file$
file.delete fid, file$ % delete the 10th file inside test_bootstrap/

Then re-zip:
Code:
include "zip_utils.bas"
list.create s, files
ZipFrom("test_bootstrap/", files, "test_bootstrap.zip", 1)

Finally delete the whole temporary folder tree:
Code:
include "zip_utils.bas"
list.create s, files
DelRecursivePath("test_bootstrap/", files, 1)

For more info on the parameters for each of these functions, refer to the header in each include file.

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Zip commands
Unread postPosted: Tue Jun 28, 2016 8:30 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5485
Location: Paris, France
There's something I forgot to do in the Zip commands, I'll have to report the commits until it's done:
it's accessing a zip file from inside assets in apk mode (ironically why I needed the zip commands in the first place! to embed in rfo-compiler)

Marc: what is the usual order the Text.Open / Byte.Open commands go in apk mode? Try on sdcard and if not found try in assets? or the opposite?

I'm just realizing all these subtleties from apk mode are written nowhere?

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Zip commands
Unread postPosted: Tue Jun 28, 2016 8:40 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5485
Location: Paris, France
I'm confused: I searched in executeBYTE_OPEN() and executeTEXT_OPEN() to see how opening a file from assets is handled, but I don't see anything about that??
"Basic.isAPK" doesn't appear anywhere in these methods, next occurence is in executeFILE_SIZE() only...
Is it handled in Basic.getBufferedReader() and Basic.getBufferedInputStream() that these methods seem to use respectively?

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Zip commands
Unread postPosted: Tue Jun 28, 2016 11:33 pm 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5485
Location: Paris, France
Hm, nevermind, ZipFile cannot work from asset:
http://stackoverflow.com/questions/1346 ... sets-files
http://stackoverflow.com/questions/1182 ... tring-path

ZipFile only takes a File as input, not an InputStream, so the only solution to unzip a file from assets is to first copy this file out of assets (sdcard) and unzip it from there.

This should be mentioned somewhere when I commit the Zip.* commands, but we don't have a place in the manual for rules in an apk.
We need to create a dedicated topic in the GitHub wiki maybe?

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Zip commands
Unread postPosted: Wed Jun 29, 2016 12:06 am 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2795
Location: Colorado, U.S.
The OPEN commands in read mode check for a file in the SDcard first. If not found, and isApk is true, they look in res, then in assets. As you said, this order is set in the Basic methods getBufferedInputStream() (for binary files) and getBufferedReader() (for text files).

You can't use getBufferedInputStream() as is because you want your BufferedInputStream wrapped around either a ZipFile object (for SDcard files) or a ZipInputStream object (for resources). But you can use the same technique. You have probably already duplicated the code in getBufferedInputStream() to work with zipped files. You'll have to duplicate the code in streamFromResource() to get a stream on a zipped asset.

You should not need to copy the resource to a file.

- Marc


Report this post
Top
 Profile  
 
 Post subject: Re: Zip commands
Unread postPosted: Wed Jun 29, 2016 12:13 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5485
Location: Paris, France
Ok :) I won't give up then.
Ideal is indeed to have Zip.* commands behave like Text.* and Byte.* commands in apk mode.

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Zip commands
Unread postPosted: Wed Jun 29, 2016 12:16 am 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2795
Location: Colorado, U.S.
There are a few places in the manual that have information about how a command runs in an apk. Very few -- either we need to add more to the manual, or we need another place to document how commands behave in an apk. I have resisted putting apk things in the manual -- it's a manual for BASIC! from the Editor, right? and it's already too complicated -- but there are getting to be a lot of apk-only things. I don't know if the manual is the right place for them -- I rather think it is not -- but we have to put that information somewhere.

- Marc


Report this post
Top
 Profile  
 
 Post subject: Re: Zip commands
Unread postPosted: Wed Jun 29, 2016 1:49 am 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
i think every command which acts differently in APK should be explaind in it's page in manual. Maybe we could avoid problems raising from after making apk.


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred