LOF: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "The LOF function is used to find the length of an OPEN file in bytes. {{PageSyntax}} : ''totalBytes&'' = LOF([#]{{Parameter|fileNumber}}) {{PageDescription}} * LOF returns the number of bytes in an OPENed designated {{Parameter|fileNumber}}. File is empty if it returns 0. * {{Parameter|fileNumber}} is the number of the opened file. '''#''' is not required. * Often used to determine the number of records in a RANDOM access file. * Can also be used...")
 
(Add information on HTTP handles)
Line 1: Line 1:
The [[LOF]] function is used to find the length of an [[OPEN]] file in bytes.
The [[LOF]] function is used to find the length of an [[OPEN]] file in bytes, or content length of an HTTP response.




Line 5: Line 5:
{{PageSyntax}}
{{PageSyntax}}
: ''totalBytes&'' = [[LOF]]([#]{{Parameter|fileNumber}})
: ''totalBytes&'' = [[LOF]]([#]{{Parameter|fileNumber}})
: ''totalBytes&'' = [[LOF]]([#]{{Parameter|httpHandle}})




{{PageDescription}}
{{PageDescription}}
* LOF returns the number of bytes in an [[OPEN]]ed designated {{Parameter|fileNumber}}. File is empty if it returns 0.
* For regular [[OPEN]]ed files:
* {{Parameter|fileNumber}} is the number of the opened file. '''#''' is not required.
** LOF returns the number of bytes in an [[OPEN]]ed designated {{Parameter|fileNumber}}. File is empty if it returns 0.
* Often used to determine the number of records in a [[RANDOM]] access file.
** {{Parameter|fileNumber}} is the number of the opened file. '''#''' is not required.
* Can also be used to avoid reading an empty file, which would create an error.
** Often used to determine the number of records in a [[RANDOM]] access file.
* LOF in '''QB64''' can return up to 9 GB (9,223,372,036 bytes) file sizes.
** Can also be used to avoid reading an empty file, which would create an error.
** LOF in '''QB64''' can return up to 9 GB (9,223,372,036 bytes) file sizes.


* For HTTP handles opened using [[_OPENCLIENT]]:
** [[LOF]] returns the length listed in the Content-Length header of the HTTP response.
** If no Content-Length header was provided on the HTTP response, then [[LOF]] return -1


{{PageExamples}}
{{PageExamples}}
Line 23: Line 28:
{{CodeEnd}}
{{CodeEnd}}


''Example:'' Reading the Content length of an HTTP response
{{CodeStart}}
{{Cl|$UNSTABLE}}:Http
h& = {{Cl|_OPENCLIENT}}("HTTP:https://qb64phoenix.com")
{{Cl|PRINT}} {{Cl|LOF}}(h&)
{{CodeEnd}}


{{PageSeeAlso}}
{{PageSeeAlso}}

Revision as of 07:46, 6 January 2023

The LOF function is used to find the length of an OPEN file in bytes, or content length of an HTTP response.


Syntax

totalBytes& = LOF([#]fileNumber)
totalBytes& = LOF([#]httpHandle)


Description

  • For regular OPENed files:
    • LOF returns the number of bytes in an OPENed designated fileNumber. File is empty if it returns 0.
    • fileNumber is the number of the opened file. # is not required.
    • Often used to determine the number of records in a RANDOM access file.
    • Can also be used to avoid reading an empty file, which would create an error.
    • LOF in QB64 can return up to 9 GB (9,223,372,036 bytes) file sizes.
  • For HTTP handles opened using _OPENCLIENT:
    • LOF returns the length listed in the Content-Length header of the HTTP response.
    • If no Content-Length header was provided on the HTTP response, then LOF return -1

Examples

Example: Finding the number of records in a RANDOM file using a TYPE variable.

  OPEN file$ FOR RANDOM AS #1 LEN = LEN(Type_variable)
  NumRecords% = LOF(1) \ RecordLEN%

Example: Reading the Content length of an HTTP response

$UNSTABLE:Http
h& = _OPENCLIENT("HTTP:https://qb64phoenix.com")
PRINT LOF(h&)

See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link