[TW5] Getting tiddlywiki file size code

38 views
Skip to first unread message

Sergey Litvinov

unread,
Aug 29, 2017, 4:09:02 PM8/29/17
to TiddlyWikiDev
Hi everyone!

I'm writing a macro to display tiddlywiki file size.

Could you please help me with the code required to withdraw the file (itself) size?

Sorry for probably stupid question, I've never written in JavaScript unfortunately)

Thanks a lot for any help!)

Eric Shulman

unread,
Aug 29, 2017, 5:40:09 PM8/29/17
to TiddlyWikiDev
On Tuesday, August 29, 2017 at 1:09:02 PM UTC-7, Sergey Litvinov wrote:

I'm writing a macro to display tiddlywiki file size.

could you please help me with the code required to withdraw the file (itself) size?


For security reasons, browsers severely restrict access to file system information.  As such, it is not possible to directly read the size of the file stored on disk.

However, there are some ways for getting the size of the *currently loaded* HTML content, by using

document.head.innerHTML.length + document.body.innerHTML.length
or
document.documentElement.innerHTML.length

Note: these values only approximate the actual file size.  For example, using Chrome's built-in Developer Tools with a downloaded copy of http://tiddlywiki.com/empty.html yields the following:

document.head.innerHTML.length + document.body.innerHTML.length
   = 1806387
document.documentElement.innerHTML.length
   = 1806430
However, the actual file size (as reported by Win10 file "Properties" dialog)
   = 1938885

perhaps this is close enough for your purposes?

let me know how it goes...

enjoy,
-e
Eric Shulman
TiddlyTools.com: "Small Tools for Big Ideas!" (tm)
InsideTiddlyWiki: The Missing Manuals


Reply all
Reply to author
Forward
0 new messages