Sign in to follow this  
Followers 0
caleb41610

Get BinaryLen() of file data, without loading the file in to a string?

8 posts in this topic

Local $sFile = @ScriptDir & "index.html"
Local $nFileReadSize = FileGetSize($sFile)
Local $hFile = FileOpen($sFile)
Local $nFileBinarySize = BinaryLen( FileRead($hFile) )
FileClose($hFile)
 
The results are:
 
$nFileReadSize == 630
$nFileBinarySize == 622
 
I'm using this to send large files in chunks, and I cannot load the whole file in to a string with FileRead() due to memory limitations.  I'm also sending it via the web using http.  So, I must get the actual BinaryLen() for the http header somehow, without loading the whole file.  I'm stumped.
 
My current method has been to load the file in chunks at the initialization stage, calculate each step, and just save the number for any file greater than the memory threshhold.  Obviously this will scale badly!
 
Any ideas?  Thanks!   :huggles:

Share this post


Link to post
Share on other sites



Use FileOpen in binary mode, else results are more or less meaningless.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Files can have BOM which could cause reading wrong size in binary mode. Probably you don't want BOM sent caleb41610?

This is just for jchd to see possible issue with his suggestion.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Yes I know well, BOM or lack of can be anything in 0, 2, 3 or 4 bytes. Not 8.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Can it be, let's say 5 bytes?

...just that I know what to say when someone asks me that?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

But would AutoIt know what to do with that BOM? What do you think?

How many characters would it read? In size of binary len or fewer? Or third?

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

My suggestion was only for a reliable file length result in binary (that's for the record).

UTF7 is a thing of the past, which AutoIt rightfully ignores.

Like trancexx knows by heart ( :bye:) UTF8 BOM is 3 bytes, UTF16 BOM (-LE or -BE) is one encoding unit, i.e. 2 bytes. UTF32 BOM (-LE or -BE) is again one encoding unit, i.e. 32-bit or 4 bytes.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0