Save/Load stack from Archive/Zip

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Save/Load stack from Archive/Zip

Post by palanolho »

Greetings everyone,

I was wondering if anyone knows if its possible to (and how):
* create a stack in memory, add some images to the stack and save the stack into an Archive/zip
* load a stack from an archive/zip into memory with all its content

If "yes you can" is the answer, will I be able to use this stack and access its content on the stand alone application?

Many thanks in advance,
- Miguel
Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Save/Load stack from Archive/Zip

Post by Simon »

Hi Miguel,
Yes you can.
Check out "create stack" and "revZipOpenArchive" in the dictionary.
Using "copy" you can then place an image on the new stack. Now you are going to want to keep track of the new images on the new stack so after the copy:

Code: Select all

put the ID of the last image of stack "Test"
Now where are you going to store that info?

Saving stack:

Code: Select all

save stack "Test" as (specialFolderPath("desktop") & "/test.rev")
Fun!

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Save/Load stack from Archive/Zip

Post by palanolho »

wait I got lost :)



I have a XML in memory (that I already save/load on the archive) and when I add the image to the stack I will store the img ID on the XML.

Code: Select all

put the ID of the last image of stack "Test"
this is to get the ID of the img I just added to the stack without having to dig it up from all imgs on that stack, correct?

Code: Select all

save stack "Test" as (specialFolderPath("desktop") & "/test.rev")
this is to store the stack on disc correct?

could I add it to my archive like this?

Code: Select all

revZipAddItemWithData myArchive , "stack.rev", myStack
Many thanks,
- Miguel
Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Save/Load stack from Archive/Zip

Post by Simon »

Hi Miguel,
Yeah I think you get it.

Here is the zip lesson;
http://lessons.runrev.com/s/lessons/m/4 ... 5-zip-tool
"revZipOpenArchive pZipFile, "write""

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Save/Load stack from Archive/Zip

Post by palanolho »

Hi everyone,

I got some time to return to this topic and was trying to implement this as suggested, however I'm having some issues.

I'm able to store a file with some text on the Archive file, BUT ... I'm not being able to store the stack on the Archive file.


This creates a test.rev file inside the ARchive containing the name of my stack (like if it was a normal txt file)

Code: Select all

global gameSupportStack -- this containsthe name of the stack I want to store
revZipAddUncompressedItemWithData projectPath, "test.rev", "gameSupportStack"
Isn't it Possible to copy/save a stack into an Archive without saving it to disk first ???
How can I do it


Note: I'm able to add the stack to the Archive IF I have a physical file on disk sing the script bellow but I really would like to do it without having to create a file on disk

Code: Select all

put (specialFolderPath("desktop") & "/support_stack.rev") into tFilePath
save stack gameSupportStack as tFilePath
revZipAddUncompressedItemWithFile projectPath, "gameSupportStack.rev", tFilePath

Many thanks in advance,
- Miguel
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Save/Load stack from Archive/Zip

Post by FourthWorld »

The Zip external is nice, but if you're only compressing a single file you can use the built-in GZip support in the compress function:

Code: Select all

put url ("binfile: "& tPathToSomeFile) into tData
put compress(tData) into tCompressedData
I'll wager you can guess the name of the function needed to decompress the data. ;)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Save/Load stack from Archive/Zip

Post by palanolho »

Actually I'm adding more than one file to the archive. The stack is just another one I would like to add.

Any ideas? :(

- Miguel
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Save/Load stack from Archive/Zip

Post by palanolho »

So, my ultimate question is:
  1. Is it possible to add a stack directly to an Archive without saving it to a file first?
  2. Is it possible to load a stack in an Archive, directly into memory, without saving it to disk first?
Many thanks in advance,
- Miguel
Post Reply