# Binary Files

The `binary_files` module provides utilities for reading and parsing Verion 0 and Version 1 Saleae Logic2
binary export files. The Version 1 format was released in June 2025. See our [support website](https://support.saleae.com/faq/technical-faq/binary-and-csv-export-formats-2025-update) for information on the new format.

## Overview

This module handles the low-level details of reading and parsing the binary file formats used by Saleae Logic devices. It's primarily used internally by the `Capture` class, but can also be used directly for advanced use cases. See the [Capture API Reference](capture.md) for more information.

It defaults to using `np.memmap()` to access (what can be) very large capture files. This allows loading into
system RAM to be done as late as practical.

## Functions

### `read_file`

```python
def read_file(file_path: Path) -> SaleaeFile
```

Reads and parses a binary file exported from Saleae Logic.

**Parameters:**
- `file_path`: Path to the binary file

**Returns:**
- A `SaleaeFile` object containing the parsed contents

## Classes

### `SaleaeFile`

Contains the parsed contents of a binary file.

**Attributes:**
- `version`: the file format version, either 0 or 1
- `type`: our internal Enum (e.g. Filetype_DigitalExport, _AnalogExport, _WaveformAdcExport, etc.)
- `contents`: The parsed contents of the file (e.g., AnalogExport_V0, DigitalExport_V1, etc.)

## Note

This module is primarily used internally by the `Capture` class. Most users should use the `Capture` class instead of working with this module directly.
The module is exposed for advanced use cases where direct access to the binary file format is needed.

## Error Handling

The module will raise appropriate errors if:
- The file cannot be found
- The file format is invalid
- The file is not an analog export
- The file is corrupted or incomplete
