Skip to content

Commit

Permalink
Add mmap_mode option to allow writing to mmaped PLY files.
Browse files Browse the repository at this point in the history
  • Loading branch information
chpatrick authored and nh2 committed Jun 16, 2024
1 parent f9c1546 commit 7440ce8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions plyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _parse_header(stream):
)

@staticmethod
def read(stream, mmap=True, known_list_len={}):
def read(stream, mmap=True, mmap_mode="c", known_list_len={}):
"""
Read PLY data from a readable file-like object or filename.
Expand Down Expand Up @@ -171,6 +171,7 @@ def read(stream, mmap=True, known_list_len={}):
data_stream = stream
for elt in data:
elt._read(data_stream, data.text, data.byte_order, mmap,
mmap_mode=mmap_mode,
known_list_len=known_list_len.get(elt.name, {}))
finally:
if must_close:
Expand Down Expand Up @@ -497,7 +498,7 @@ def describe(data, name, len_types={}, val_types={},

return elt

def _read(self, stream, text, byte_order, mmap,
def _read(self, stream, text, byte_order, mmap, mmap_mode,
known_list_len={}):
"""
Read the actual data from a PLY file.
Expand Down Expand Up @@ -581,7 +582,7 @@ def _read_mmap(self, stream, byte_order, known_list_len):
if max_bytes < num_bytes:
raise PlyElementParseError("early end-of-file", self,
max_bytes // dtype.itemsize)
self._data = _np.memmap(stream, dtype, 'c', offset, self.count)
self._data = _np.memmap(stream, dtype, mmap_mode, offset, self.count)
# Fix stream position
stream.seek(offset + self.count * dtype.itemsize)
# remove any extra properties added
Expand Down

0 comments on commit 7440ce8

Please sign in to comment.