How do I get the byte size of a substack?

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
trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

How do I get the byte size of a substack?

Post by trevix » Tue Feb 12, 2019 8:04 pm

I would like to get by script the file size of a sub stack (well, also of a stack).
Do I have to go the long way?
https://forums.livecode.com/viewtopic.php?t=5397

Thanks
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How do I get the byte size of a substack?

Post by bogs » Tue Feb 12, 2019 8:19 pm

Not sure what you mean by 'the long way' ?

I'm assuming (bad habit there eh wot?) that you already know at least the relative location of the stack and substack your going to check the size of?

If that is the case, you can skip about half the lines in the two examples on that page trying to determine where the stack is located, so whats left?

Those two examples aside though, why wouldn't you just get item 2 of the detailed files?
The detailed files form returns a list of files, one file per line. Each line contains the following attributes, separated by commas:
* The file's name, URL-encoded
* The file's size in bytes (on Mac OS and OS X systems, the size of the file's data fork)
* The resource fork size in bytes (Mac OS and OS X systems only)
* The file's creation date in seconds (Mac OS, OS X, and Windows systems only)
* The file's modification date in seconds
* The file's last-accessed date in seconds (Unix, OS X and Windows systems only)
* The file's last-backup date in seconds (Mac OS and OS X systems only)
* The file's owner (Unix and OS X systems only)
* The file's group owner (Unix and OS X systems only)
* The file's access permissions
* The file's creator and file type (Mac OS and OS X only)
Any attribute that is not supported on the current system is reported as empty.
Selection_001.png
1, 2, ....
Selection_001.png (10.2 KiB) Viewed 6409 times
I don't know if that would work for a substack, but it should for a main one. I suppose you could always temporarily write the substack out somewhere too.

We haven't even discussed just shelling out and using the OS utilities for doing the same thing, which sometimes are easier to work with.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How do I get the byte size of a substack?

Post by FourthWorld » Tue Feb 12, 2019 8:41 pm

For what purpose? The size on disk is not the size in RAM. Once we know the goal we can advise on how to achieve it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: How do I get the byte size of a substack?

Post by trevix » Tue Feb 12, 2019 11:27 pm

I am uploading from LC, using the Filemaker data API, stacks to the remote DB.
I also need to load substack of the same main stack that is doing the routine.
I convert them and put in a var that I upload:

Code: Select all

 put URL ("binfile:/" & tPath) into tFile
put  textEncode(base64Encode(tFile)) into tVar
It works fine, for upload and, on reverse, for download.

Together with the stack, I upload a series of info, like the name, the creation date, description, etc.
I would like also, in Filemaker, to show the size of the stack.

This is the reason for my question.

In effect, I am so used to easy functions of LC, that I hoped for some native GetTheSize(thePath).
May be I can get a rough size of the file from the length of the binary, but I see no corrispondence with real size given by the OS.

So I was just checking out if i missed something from the manual.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How do I get the byte size of a substack?

Post by bogs » Wed Feb 13, 2019 12:09 am

trevix wrote:
Tue Feb 12, 2019 11:27 pm
In effect, I am so used to easy functions of LC, that I hoped for some native GetTheSize(thePath).
item 2 of the detailed files will do just that, as shown above. There are probably at least 6 more easy ways to do it as well.
Image

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How do I get the byte size of a substack?

Post by Klaus » Wed Feb 13, 2019 3:16 pm

Hi Trevix,

why not create your own GetTheSize(thePath) funktion?
Will take as much time as setting up this thread! :-D


Best

Klaus

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: How do I get the byte size of a substack?

Post by bogs » Wed Feb 13, 2019 3:49 pm

Klaus wrote:
Wed Feb 13, 2019 3:16 pm
Will take as much time as setting up this thread!
Where is the fun in that ?! :twisted:
Also, would such a function use the detailed files at all? :twisted: :twisted:
Image

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How do I get the byte size of a substack?

Post by Klaus » Wed Feb 13, 2019 3:57 pm

bogs wrote:
Wed Feb 13, 2019 3:49 pm
Where is the fun in that ?! :twisted:
Well, teh creation itself would be fun, right?
bogs wrote:
Wed Feb 13, 2019 3:49 pm
Also, would such a function use the detailed files at all? :twisted: :twisted:
If you know another ways (ecept SHELL) to do this in LC, I'm all ears. :-)

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How do I get the byte size of a substack?

Post by jacque » Wed Feb 13, 2019 4:58 pm

Since the file is in a variable I'd think you could just get the length of the variable.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: How do I get the byte size of a substack?

Post by trevix » Wed Feb 13, 2019 5:08 pm

jacque, as I said:
May be I can get a rough size of the file from the length of the binary, but I see no corrispondence with real size given by the OS.
Couldn't find proportionality
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How do I get the byte size of a substack?

Post by jacque » Wed Feb 13, 2019 6:02 pm

Ah. Right, I missed that. On the other hand, if the variable is what you're uploading, wouldn't the length of it be the actual size? It wouldn't be the same as the memory footprint but it should be the size for transport. (This may be wrong-think, I've never compared the two.)

The only other way I can think of is to query the files as Bogs suggested.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How do I get the byte size of a substack?

Post by FourthWorld » Wed Feb 13, 2019 6:37 pm

Ah, so we're talking about stack files, not a substack within a stack file. Much simpler.

Getting the length used to be sufficient, back when LC only handled single-byte encodings. But now that LiveCode supports multiple encodings Mark Waddingham recommends using the byte chunk type for binary data, e.g.:

Code: Select all

get the number of bytes of tVar
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: How do I get the byte size of a substack?

Post by trevix » Thu Feb 14, 2019 9:37 am

PERFECT.
This is what I needed.
Thank you
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How do I get the byte size of a substack?

Post by FourthWorld » Thu Feb 14, 2019 7:33 pm

Maybe. If you've already done a binary read of the file into memory, that will help. But if the file is still on disk, the function below will help.

One tip for geting help here is distinguishing between stack files and substacks: A stack file is a file in LiveCode format that contains one mainstack and zero or more substacks.

Obtaining the size of any specific part of a LiveCode file is a different task than just getting the size of a file.

The FileSize function here provides the latter:

Code: Select all

-- Calling example:
on mouseUp
   put "/home/rg/somefolder/somefile.txt" into tFilePath
   put FileSize(tFilePath) into tSize
   put tSize
end mouseUp


-- FileSize takes the path to a file and returns the
-- file's size in bytes:
function FileSize pFilePath
   set the itemdel to "/"
   put files(item 1 to -2 of pFilePath, "detailed") into tFiles
   filter tFiles with urlEncode(last item of pFilePath)&",*"
   set the itemdel to ","
   return item 2 of tFiles
end FileSize
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”