# 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:
```rust
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`:
```rust
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:
```rust
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`
```toml
[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:
```sh
dxfbin < drawing.dxf > drawing.bin.dxf
```
## License
ISC