From 108e7c8a1b0b1b397cc31d7eff109d3345825ac8 Mon Sep 17 00:00:00 2001 From: M Bouchard Guillaume Date: Fri, 26 Nov 2010 13:26:46 +0000 Subject: Better heuristic for ASCII/Binary STL file format detection --- io_mesh_stl/stl_utils.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'io_mesh_stl') diff --git a/io_mesh_stl/stl_utils.py b/io_mesh_stl/stl_utils.py index 912df356..734204b8 100644 --- a/io_mesh_stl/stl_utils.py +++ b/io_mesh_stl/stl_utils.py @@ -62,11 +62,25 @@ class ListDict(dict): return value +BINARY_HEADER = 80 +BINARY_STRIDE = 12 * 4 + 2 + +def _is_ascii_file(data): + ''' + This function returns True if the data represents an ASCII file. + + Please note that a False value does not necessary means that the data + represents a binary file. It can be a (very *RARE* in real life, but + can easily be forged) ascii file. + ''' + size = struct.unpack_from('