summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorboydgreenfield <boyd.greenfield@gmail.com>2014-05-05 14:56:14 -0700
committerboydgreenfield <boyd.greenfield@gmail.com>2014-05-05 14:56:14 -0700
commitc210e1255cc902130ba76d4d1f014ac0f724d145 (patch)
treeab350bfe5e76c452bfede5cdf8190590bf43ad1e /lib
parent88cb4850cea651f78612a12e3fd3ba704109b0b7 (diff)
downloadNim-c210e1255cc902130ba76d4d1f014ac0f724d145.tar.gz
Clarify newFileSize & mappedSize params in memfiles.open() docs
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/memfiles.nim19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim
index 807f3da43..97220b90b 100644
--- a/lib/pure/memfiles.nim
+++ b/lib/pure/memfiles.nim
@@ -74,9 +74,22 @@ proc unmapMem*(f: var TMemFile, p: pointer, size: int) =
 proc open*(filename: string, mode: TFileMode = fmRead,
            mappedSize = -1, offset = 0, newFileSize = -1): TMemFile =
   ## opens a memory mapped file. If this fails, ``EOS`` is raised.
-  ## `newFileSize` can only be set if the file is not opened with ``fmRead``
-  ## access. `mappedSize` and `offset` can be used to map only a slice of
-  ## the file.
+  ## `newFileSize` can only be set if the file does not exist and is opened
+  ## with write access (e.g., with fmReadWrite). `mappedSize` and `offset`
+  ## 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:
   assert newFileSize == -1 or mode != fmRead