API Documentation¶
littlefs module¶
-
class
littlefs.
FileHandle
(fs, fh)¶ -
close
()¶ Flush and close the IO object.
This method has no effect if the file is already closed.
-
flush
()¶ Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
-
readable
()¶ Return whether object was opened for reading.
If False, read() will raise OSError.
-
readall
()¶ Read until EOF, using multiple read() call.
-
readinto
(b)¶
-
seek
(offset, whence=0)¶ Change stream position.
Change the stream position to the given byte offset. The offset is interpreted relative to the position indicated by whence. Values for whence are:
- 0 – start of stream (the default); offset should be zero or positive
- 1 – current stream position; offset may be negative
- 2 – end of stream; offset is usually negative
Return the new absolute position.
-
seekable
()¶ Return whether object supports random access.
If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().
-
tell
()¶ Return current stream position.
-
truncate
(size=None) → int¶ Truncate file to size bytes.
File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.
-
writable
()¶ Return whether object was opened for writing.
If False, write() will raise OSError.
-
write
(data)¶
-
-
class
littlefs.
LittleFS
(context: UserContext = None, **kwargs)¶ Littlefs file system
-
context
¶ User context of the file system
-
format
() → int¶ Format the underlying buffer
-
listdir
(path='.') → List[str]¶ List directory content
List the content of a directory. This function uses
scandir()
internally. Usingscandir()
might be better if you are searching for a specific file or need access to thelittlefs.lfs.LFSStat
of the files.
-
makedirs
(name: str, exist_ok=False)¶ Recursive directory creation function.
-
mkdir
(path: str) → int¶ Create a new directory
-
mount
() → int¶ Mount the underlying buffer
-
open
(fname: str, mode='r', buffering: int = -1, encoding: str = None, errors: str = None, newline: str = None) → IO¶ Open a file.
mode
is an optional string that specifies the mode in which the file is opened and is analogous to the built-inio.open()
function. Files opened in text mode (default) will take and return str objects. Files opened in binary mode will take and return byte-like objects.Parameters: - fname (str) – The path to the file to open.
- mode (str) – Specifies the mode in which the file is opened.
- buffering (int) – Specifies the buffering policy. Pass 0 to disable buffering in binary mode.
- encoding (str) – Text encoding to use. (text mode only)
- errors (str) – Specifies how encoding and decoding errors are to be handled. (text mode only)
- newline (str) – Controls how universal newlines mode works. (text mode only)
-
remove
(path: str) → int¶ Remove a file or directory
If the path to remove is a directory, the directory must be empty.
Parameters: path (str) – The path to the file or directory to remove.
-
removedirs
(name)¶ Remove directories recursively
This works like
remove()
but if the leaf directory is empty after the successfull removal ofname
, the function tries to recursively remove all parent directories which are also empty.
-
rename
(src: str, dst: str) → int¶ Rename a file or directory
-
scandir
(path='.') → Iterator[LFSStat]¶ List directory content
-
stat
(path: str) → LFSStat¶ Get the status of a file or directory
-
walk
(top: str) → Iterator[Tuple[str, List[str], List[str]]]¶ Generate the file names in a directory tree
Generate the file and directory names in a directory tree by walking the tree top-down. This functions closely resembels the behaviour of
os.stat()
.Each iteration yields a tuple containing three elements:
- The root of the currently processed element
- A list of directorys located in the root
- A list of filenames located in the root
-
littlefs.context module¶
-
class
littlefs.context.
UserContext
(buffsize: int)¶ Basic User Context Implementation
-
erase
(cfg: LFSConfig, block: int) → int¶ Erase a block
Parameters:
-
prog
(cfg: LFSConfig, block: int, off: int, data: bytes) → int¶ program data
Parameters:
-
read
(cfg: LFSConfig, block: int, off: int, size: int) → bytearray¶ read data
Parameters:
-
littlefs.lfs module¶
-
class
littlefs.lfs.
LFSStat
¶ Littlefs File / Directory status
-
name
¶ Alias for field number 2
-
size
¶ Alias for field number 1
-
type
¶ Alias for field number 0
-
-
class
littlefs.lfs.
LFSConfig
(context=None, **kwargs)¶ -
attr_max
¶
-
block_count
¶
-
block_size
¶
-
cache_size
¶
-
file_max
¶
-
lookahead_size
¶
-
name_max
¶
-
prog_size
¶
-
read_size
¶
-
-
class
littlefs.lfs.
LFSDirectory
¶
-
class
littlefs.lfs.
LFSFileFlag
¶ Littlefs file mode flags
-
append
= 2048¶
-
creat
= 256¶
-
excl
= 512¶
-
rdonly
= 1¶
-
rdwr
= 3¶
-
trunc
= 1024¶
-
wronly
= 2¶
-
-
class
littlefs.lfs.
LFSFilesystem
¶
-
littlefs.lfs.
dir_close
(LFSFilesystem fs, LFSDirectory dh)¶
-
littlefs.lfs.
dir_open
(LFSFilesystem fs, path)¶
-
littlefs.lfs.
dir_read
(LFSFilesystem fs, LFSDirectory dh)¶
-
littlefs.lfs.
dir_rewind
(LFSFilesystem fs, LFSDirectory dh)¶
-
littlefs.lfs.
dir_tell
(LFSFilesystem fs, LFSDirectory dh)¶
-
littlefs.lfs.
file_close
(LFSFilesystem fs, LFSFile fh)¶
-
littlefs.lfs.
file_open
(LFSFilesystem fs, path, flags)¶
-
littlefs.lfs.
file_open_cfg
(self, path, flags, config)¶
-
littlefs.lfs.
file_read
(LFSFilesystem fs, LFSFile fh, size)¶
-
littlefs.lfs.
file_rewind
(LFSFilesystem fs, LFSFile fh)¶
-
littlefs.lfs.
file_seek
(LFSFilesystem fs, LFSFile fh, off, whence)¶
-
littlefs.lfs.
file_size
(LFSFilesystem fs, LFSFile fh)¶
-
littlefs.lfs.
file_sync
(LFSFilesystem fs, LFSFile fh)¶
-
littlefs.lfs.
file_tell
(LFSFilesystem fs, LFSFile fh)¶
-
littlefs.lfs.
file_truncate
(LFSFilesystem fs, LFSFile fh, size)¶
-
littlefs.lfs.
file_write
(LFSFilesystem fs, LFSFile fh, data)¶
-
littlefs.lfs.
format
(LFSFilesystem fs, LFSConfig cfg)¶ Format the filesystem
-
littlefs.lfs.
fs_size
(LFSFilesystem fs)¶
-
littlefs.lfs.
getattr
(LFSFilesystem fs, path, type, buffer, size)¶
-
littlefs.lfs.
mkdir
(LFSFilesystem fs, path)¶
-
littlefs.lfs.
mount
(LFSFilesystem fs, LFSConfig cfg)¶ Mount the filesystem
-
littlefs.lfs.
remove
(LFSFilesystem fs, path)¶ Remove a file or directory
If removing a direcotry, the directory must be empty.
-
littlefs.lfs.
removeattr
(LFSFilesystem fs, path, type)¶
-
littlefs.lfs.
rename
(LFSFilesystem fs, oldpath, newpath)¶ Rename or move a file or directory
If the destination exists, it must match the source in type. If the destination is a directory, the directory must be empty.
-
littlefs.lfs.
setattr
(LFSFilesystem fs, path, type, buffer, size)¶
-
littlefs.lfs.
stat
(LFSFilesystem fs, path)¶ Find info about a file or directory
-
littlefs.lfs.
unmount
(LFSFilesystem fs)¶ Unmount the filesystem
This does nothing beside releasing any allocated resources