Skip to content

Commit 8adfb9c

Browse files
Still support StringIO
1 parent 0896061 commit 8adfb9c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pypcd/pypcd.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
try:
2020
from StringIO import StringIO, BytesIO
2121
except ImportError:
22-
from io import BytesIO
22+
from io import BytesIO, StringIO
2323

2424
HAS_SENSOR_MSGS = True
2525
try:
@@ -317,6 +317,12 @@ def point_cloud_from_buffer(buf):
317317
return pc
318318

319319

320+
def point_cloud_from_string(string):
321+
with StringIO(string) as fileobj:
322+
pc = point_cloud_from_fileobj(fileobj)
323+
return pc
324+
325+
320326
def point_cloud_to_fileobj(pc, fileobj, data_compression=None):
321327
""" Write pointcloud as .pcd to fileobj.
322328
If data_compression is not None it overrides pc.data.
@@ -745,9 +751,17 @@ def from_path(fname):
745751
def from_fileobj(fileobj):
746752
return point_cloud_from_fileobj(fileobj)
747753

754+
@staticmethod
755+
def from_string(string):
756+
return point_cloud_from_string(string)
757+
748758
@staticmethod
749759
def from_buffer(buf):
750-
return point_cloud_from_buffer(buf)
760+
try:
761+
return point_cloud_from_buffer(buf)
762+
except TypeError:
763+
# The old method could handle strings. The new one should also be able to.
764+
return PointCloud.from_string(buf)
751765

752766
@staticmethod
753767
def from_array(arr):

0 commit comments

Comments
 (0)