Difference between revisions of "X file:seek"

From GiderosMobile
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
'''Available since:''' Gideros 2011.6<br/>
 
'''Available since:''' Gideros 2011.6<br/>
'''Class:''' [[file|file]]<br/>
+
'''Class:''' [[X File]]<br/>
  
 
=== Description ===
 
=== Description ===
Line 30: Line 30:
 
'''Returns''' (number) the position in file measured in bytes from the beginning of the file<br/>
 
'''Returns''' (number) the position in file measured in bytes from the beginning of the file<br/>
  
{{File}}
+
{{X File}}

Latest revision as of 22:39, 24 January 2026

Available since: Gideros 2011.6
Class: X File

Description

Sets and gets the file position, measured from the beginning of the file to the position given by offset plus a base specified by the string whence.

(number) = file:seek(whence, offset)


Possible values for whence:

  • "set": base is position 0 (beginning of the file)
  • "cur": base is current position
  • "end": base is end of file

In case of success, function seek returns the final file position, measured in bytes from the beginning of the file. If this function fails, it returns nil, plus a string describing the error.


Therefore:

  • file:seek() returns the current file position, without changing it
  • file:seek("set") sets the position to the beginning of the file (and returns 0)
  • file:seek("end") sets the position to the end of the file, and returns its size

Parameters

whence: (string) setting the base point for offset optional (default = "cur")
offset: (number) offset to set position to optional (default = 0)

Return values

Returns (number) the position in file measured in bytes from the beginning of the file