Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches

Kodi's file class. More...

Classes

class  XBMCAddon::xbmcvfs::File
 

Functions

 XBMCAddon::xbmcvfs::File::File (const String &filepath, const char *mode=NULL)
 
 XBMCAddon::xbmcvfs::File::~File () override
 
 XBMCAddon::xbmcvfs::File::read (...)
 

Function: read([bytes])


Read file parts as string.
 
 XBMCAddon::xbmcvfs::File::readBytes (...)
 

Function: readBytes(numbytes)


Read bytes from file.
 
 XBMCAddon::xbmcvfs::File::write (...)
 

Function: write(buffer)


To write given data in file.
 
 XBMCAddon::xbmcvfs::File::size ()
 

Function: size()


Get the file size.
 
 XBMCAddon::xbmcvfs::File::seek (...)
 

Function: seek(seekBytes, iWhence)


Seek to position in file.
 
 XBMCAddon::xbmcvfs::File::tell ()
 

Function: tell()


Get the current position in the file.
 
 XBMCAddon::xbmcvfs::File::close ()
 

Function: close()


Close opened file.
 
const XFILE::CFileXBMCAddon::xbmcvfs::File::getFile () const
 

Detailed Description

Kodi's file class.

Class: xbmcvfs.File(filepath, [mode])

Parameters
filepathstring Selected file path
mode[opt] string Additional mode options (if no mode is supplied, the default is Open for Read).
Mode Description
w Open for write

v19 Python API changes
Added context manager support

Example:

..
f = xbmcvfs.File(file, 'w')
..

Example (v19 and up):

..
with xbmcvfs.File(file, 'w') as f:
..
..

Function Documentation

◆ close()

XBMCAddon::xbmcvfs::File::close ( )

Function: close()


Close opened file.


Example:

..
f = xbmcvfs.File(file)
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
..
..

◆ File()

XBMCAddon::xbmcvfs::File::File ( const String & filepath,
const char * mode = NULL )
inline

◆ getFile()

const XFILE::CFile * XBMCAddon::xbmcvfs::File::getFile ( ) const
inline

◆ read()

XBMCAddon::xbmcvfs::File::read ( ...)

Function: read([bytes])


Read file parts as string.

Parameters
bytes[opt] How many bytes to read - if not set it will read the whole file
Returns
string

Example:

..
f = xbmcvfs.File(file)
b = f.read()
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as file:
b = f.read()
..

◆ readBytes()

XbmcCommons::Buffer XBMCAddon::xbmcvfs::File::readBytes ( ...)

Function: readBytes(numbytes)


Read bytes from file.

Parameters
numbytesHow many bytes to read [opt]- if not set it will read the whole file
Returns
bytearray

Example:

..
f = xbmcvfs.File(file)
b = f.readBytes()
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
b = f.readBytes()
..

◆ seek()

XBMCAddon::xbmcvfs::File::seek ( ...)

Function: seek(seekBytes, iWhence)


Seek to position in file.

Parameters
seekBytesposition in the file
iWhence[opt] where in a file to seek from[0 beginning, 1 current , 2 end position]

v19 Python API changes
Function changed. param iWhence is now optional.

Example:

..
f = xbmcvfs.File(file)
result = f.seek(8129, 0)
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
result = f.seek(8129, 0)
..

◆ size()

XBMCAddon::xbmcvfs::File::size ( )

Function: size()


Get the file size.

Returns
The file size

Example:

..
f = xbmcvfs.File(file)
s = f.size()
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
s = f.size()
..

◆ tell()

XBMCAddon::xbmcvfs::File::tell ( )

Function: tell()


Get the current position in the file.

Returns
The file position

v19 Python API changes
New function added

Example:

..
f = xbmcvfs.File(file)
s = f.tell()
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
s = f.tell()
..

◆ write()

bool XBMCAddon::xbmcvfs::File::write ( ...)

Function: write(buffer)


To write given data in file.

Parameters
bufferBuffer to write to file
Returns
True on success.

Example:

..
f = xbmcvfs.File(file, 'w')
result = f.write(buffer)
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file, 'w') as f:
result = f.write(buffer)
..

◆ ~File()

XBMCAddon::xbmcvfs::File::~File ( )
inlineoverride