Clarify newFileSize & mappedSize params in memfiles.open() docs
This commit is contained in:
parent
88cb4850ce
commit
c210e1255c
1 changed files with 16 additions and 3 deletions
|
|
@ -74,9 +74,22 @@ proc unmapMem*(f: var TMemFile, p: pointer, size: int) =
|
||||||
proc open*(filename: string, mode: TFileMode = fmRead,
|
proc open*(filename: string, mode: TFileMode = fmRead,
|
||||||
mappedSize = -1, offset = 0, newFileSize = -1): TMemFile =
|
mappedSize = -1, offset = 0, newFileSize = -1): TMemFile =
|
||||||
## opens a memory mapped file. If this fails, ``EOS`` is raised.
|
## opens a memory mapped file. If this fails, ``EOS`` is raised.
|
||||||
## `newFileSize` can only be set if the file is not opened with ``fmRead``
|
## `newFileSize` can only be set if the file does not exist and is opened
|
||||||
## access. `mappedSize` and `offset` can be used to map only a slice of
|
## with write access (e.g., with fmReadWrite). `mappedSize` and `offset`
|
||||||
## the file.
|
## can be used to map only a slice of the file. Example:
|
||||||
|
##
|
||||||
|
## .. code-block:: nimrod
|
||||||
|
## var
|
||||||
|
## mm, mm_full, mm_half: TMemFile
|
||||||
|
##
|
||||||
|
## mm = memfiles.open("/tmp/test.mmap", mode = fmWrite, newFileSize = 1024) # Create a new file
|
||||||
|
## mm.close()
|
||||||
|
##
|
||||||
|
## # Read the whole file, would fail if newFileSize was set
|
||||||
|
## mm_full = memfiles.open("/tmp/test.mmap", mode = fmReadWrite, mappedSize = -1)
|
||||||
|
##
|
||||||
|
## # Read the first 512 bytes
|
||||||
|
## mm_half = memfiles.open("/tmp/test.mmap", mode = fmReadWrite, mappedSize = 512)
|
||||||
|
|
||||||
# The file can be resized only when write mode is used:
|
# The file can be resized only when write mode is used:
|
||||||
assert newFileSize == -1 or mode != fmRead
|
assert newFileSize == -1 or mode != fmRead
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue