Skip to content

xorgy/dxfbin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dxfbin

Streaming text DXF to binary DXF converter.

Converts AutoCAD text-format DXF files to the binary DXF format without interpreting the drawing structure. Each group code/value pair is read, typed according to the DXF group code specification, and written in its binary encoding. The conversion is streaming and no_std-compatible.

Library usage

One-shot conversion from a byte slice:

use dxfbin::{BinarySink, convert_all};

let text_dxf = b"  0\nSECTION\n  2\nHEADER\n  0\nENDSEC\n  0\nEOF\n";
let mut out = Vec::new();
let mut sink = BinarySink::new(&mut out);
convert_all(text_dxf, &mut sink).unwrap();

Streaming conversion via std::io::Read:

use dxfbin::StreamConverter;
use std::io::{BufReader, Read};

let text_dxf = b"  0\nSECTION\n  2\nHEADER\n  0\nENDSEC\n  0\nEOF\n";
let mut converter = StreamConverter::new(BufReader::new(&text_dxf[..]));
let mut binary = Vec::new();
converter.read_to_end(&mut binary).unwrap();

Incremental feeding for custom buffering:

use dxfbin::{BinarySink, Converter};

let mut converter = Converter::new();
let mut out = Vec::new();
let mut sink = BinarySink::new(&mut out);
let chunk = b"  0\nEOF\n";
converter.feed(chunk, &mut sink).unwrap();

Typed sink

The [Sink] trait receives typed values (boolean, i16, i32, i64, f64, string, binary chunk) rather than raw bytes, so implementations can inspect or transform values by type.

no_std

[dependencies]
dxfbin = { version = "0.1", default-features = false }

The std feature (on by default) adds the StreamConverter adapter.

CLI

The crate includes a dxfbin binary that reads text DXF from stdin and writes binary DXF to stdout:

dxfbin < drawing.dxf > drawing.bin.dxf

License

ISC

About

Streaming text DXF to binary DXF conversion library.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages