Is it possible to open a file directly from a byte array instead of reading a file?
thanks,
Alfonso
Kirill Gavrilov Wed, 05/24/2017 - 09:17
There is not such functionality (yet).
The feature status can be tracked within issue #0027342 on bug tracker (don't be confused by current status "resolved", existing patch is not ready for using).
OCCT 7.5.0 has been introduced support for reading STEP files from a C++ stream.
So far, nobody reported the feature request for writing STEP file into stream on OCCT Bugtracker - you can be first: https://dev.opencascade.org/index.php?q=home/get_involved
Hello it seems like the write to Stream Issue has also bin resolved for OCC v7.7.0
Could someone post a working example for both reading from and writing to byte[]?
Also is this only for STEP or can I also import and export for example GLTFs from/to byte[]?
Thank you.
Unfortunately, you can't export/import GLTF to/from any buffers yet. Only file. If it is necessary, we can create a ticket to impliment ability to work RWMesh ToolKit (Gltf, Obj, Ply) with stream.
Hello,
I have come across this again.
I would say if not necessary it would definitely be useful to be able to write formats like gltf(.glb) to a stream/buffer.
I would say if not necessary it would definitely be useful to be able to write formats like gltf(.glb) to a stream/buffer.
glTF file format is multi-file by design, so that only in case of packing everything into a binary .glb version of the format it is possible to have a single file. But glb format specification makes it difficult writing an efficient writer, that would be able done all the work directly into a stream in a 1 pass.
So that current implementation of RWGltf_CafWriter performs export into .glb in 2 passes - first it writes all binary data into temporary file (as model might be quite large in size - it might be not a good idea to allocate it in memory), then generates JSON based on offsets in binary data, writes it into final file, copies content of a temporary file and deletes this temporary file.
Dealing with external streams (e.g. not a normal file) would make implementation less predictable. You may expect, that an 'ideal' glTF writer would be able to write output directly into some HTTP streaming interface, but glTF writer is not that plain simple and an attempt to avoid creation of a temporary file on a local server storage (or even memory-mapped FS) could lead to considerable slowdown of actual generation/transfer process.
Note that you may already use streams with OCCT through defining an own protocol (something like myproc:// and pass file names with this prefix) via OSD_FileSystem::AddDefaultProtocol() interface. Unlike passing a single std::istream or std::ostream, this interface allows processing formats that work with multiple files (like STEP/glTF/OBJ file referring to external references, expected to be placed within the same folder as the main file). But file system interface is more complicated to implement and OSD_FileSystem is incomplete in current state (it lacks methods for deleting, copying files and exploring folders).
Wed, 05/24/2017 - 09:17
There is not such functionality (yet).
The feature status can be tracked within issue #0027342 on bug tracker (don't be confused by current status "resolved", existing patch is not ready for using).
Mon, 05/29/2017 - 08:20
Thanks for the update, I hope it supports C++ streams soon.
All the best,
Alfonso
Fri, 10/23/2020 - 19:07
Is there any insight on when this will be available for writing step files?
Best regards,
Martin
Mon, 11/09/2020 - 12:57
OCCT 7.5.0 has been introduced support for reading STEP files from a C++ stream.
So far, nobody reported the feature request for writing STEP file into stream on OCCT Bugtracker - you can be first:
https://dev.opencascade.org/index.php?q=home/get_involved
Fri, 05/14/2021 - 10:00
add this write stream feature in here: #0032350
Tue, 11/01/2022 - 18:52
Hello it seems like the write to Stream Issue has also bin resolved for OCC v7.7.0
Could someone post a working example for both reading from and writing to byte[]?
Also is this only for STEP or can I also import and export for example GLTFs from/to byte[]?
Thank you.
Tue, 11/01/2022 - 19:59
Jan Selchow wrote
"resolved" bug state doesn't mean integration, it means that somebody provided a patch for review.
Wed, 11/02/2022 - 15:20
Hello,
Writing a STEP file to a stream is integrated into ver. 7.7
Best regards, Dmitrii.
Wed, 11/02/2022 - 18:30
Additionally, to work with "buffer" you can use a special C++ class - std::ostringstream.
Unfortunately, you can't export/import GLTF to/from any buffers yet. Only file. If it is necessary, we can create a ticket to impliment ability to work RWMesh ToolKit (Gltf, Obj, Ply) with stream.
Best regards, Dmitrii.
Wed, 07/10/2024 - 17:15
Hello,
I have come across this again.
I would say if not necessary it would definitely be useful to be able to write formats like gltf(.glb) to a stream/buffer.
Wed, 07/10/2024 - 17:52
Hello, thank you for your suggestion. Implementing stream export support for DE components one of the features that have interest from community. The issue is 0030844: Data Exchange - Support import from and export to stream for data exchange interface - MantisBT (opencascade.org). New subtask will be created later.
Import from stream into GLTF are supported now.
You are free to take a part in our survey: Shape the Future of OCCT! Your Opinion Matters! - Forum Open Cascade Technology
Best regards, Dmitrii.
Wed, 07/10/2024 - 20:17
Jan Selchow wrote:
glTF file format is multi-file by design, so that only in case of packing everything into a binary
.glb
version of the format it is possible to have a single file. Butglb
format specification makes it difficult writing an efficient writer, that would be able done all the work directly into a stream in a 1 pass.So that current implementation of
RWGltf_CafWriter
performs export into.glb
in 2 passes - first it writes all binary data into temporary file (as model might be quite large in size - it might be not a good idea to allocate it in memory), then generates JSON based on offsets in binary data, writes it into final file, copies content of a temporary file and deletes this temporary file.Dealing with external streams (e.g. not a normal file) would make implementation less predictable. You may expect, that an 'ideal' glTF writer would be able to write output directly into some HTTP streaming interface, but glTF writer is not that plain simple and an attempt to avoid creation of a temporary file on a local server storage (or even memory-mapped FS) could lead to considerable slowdown of actual generation/transfer process.
Note that you may already use streams with OCCT through defining an own protocol (something like
myproc://
and pass file names with this prefix) viaOSD_FileSystem::AddDefaultProtocol()
interface. Unlike passing a singlestd::istream
orstd::ostream
, this interface allows processing formats that work with multiple files (like STEP/glTF/OBJ file referring to external references, expected to be placed within the same folder as the main file). But file system interface is more complicated to implement andOSD_FileSystem
is incomplete in current state (it lacks methods for deleting, copying files and exploring folders).