Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "darn-dmap"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
rust-version = "1.63.0"
rust-version = "1.85.1"
authors = ["Remington Rohel"]
description = "SuperDARN DMAP file format I/O"
repository = "https://github.com/SuperDARNCanada/dmap"
Expand All @@ -16,12 +16,17 @@ include = ["src/**/*.rs"]
[lib]
name = "dmap"

# "cdylib" is necessary to produce a shared library for Python to import from.
# cdylib is needed when building the optional Python extension module.
crate-type = ["cdylib", "rlib"]

[features]
default = []
python = ["dep:pyo3", "dep:numpy"]

[dependencies]
pyo3 = { version = "0.26.0", features = ["extension-module", "indexmap", "abi3-py38"] }
numpy = "0.26.0"
ndarray = "0.16"
pyo3 = { version = "0.26.0", optional = true, features = ["extension-module", "indexmap", "abi3-py38"] }
numpy = { version = "0.26.0", optional = true }
indexmap = "2.3.0"
itertools = "0.13.0"
rayon = "1.10.0"
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "darn-dmap"
version = "0.8.0"
version = "0.8.1"
requires-python = ">=3.8"
authors = [
{ name = "Remington Rohel" }
Expand All @@ -26,6 +26,7 @@ python-source = "python"
module-name = "dmap.dmap_rs"
bindings = "pyo3"
profile = "release"
features = ["python"]
compatibility = "manylinux2014"
auditwheel = "repair"
strip = true
Expand Down
2 changes: 0 additions & 2 deletions src/convenience.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ pub(crate) fn split_results<T, E>(dmap_results: Vec<Result<T, E>>) -> (Vec<T>, V

(ok_inners, error_inners, bad_indices)
}


5 changes: 4 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Error type for `dmap`.
#[cfg(feature = "python")]
use pyo3::exceptions::{PyIOError, PyValueError};
#[cfg(feature = "python")]
use pyo3::PyErr;
use thiserror::Error;

Expand Down Expand Up @@ -38,7 +40,7 @@ pub enum DmapError {
/// Bytes cannot be interpreted as a DMAP field.
#[error("{0}")]
InvalidField(String),

/// Index out of bounds.
#[error("{0}")]
InvalidIndex(i32),
Expand All @@ -48,6 +50,7 @@ pub enum DmapError {
BadRecords(Vec<usize>, String),
}

#[cfg(feature = "python")]
impl From<DmapError> for PyErr {
fn from(value: DmapError) -> Self {
let msg = value.to_string();
Expand Down
14 changes: 7 additions & 7 deletions src/io.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Utility functions for file operations.

use crate::compression::{compress_bz2, detect_bz2};
use crate::parser::Parser;
use crate::types::DmapType;
use crate::DmapError;
use bzip2::read::BzDecoder;
use std::ffi::OsStr;
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::path::Path;
use crate::parser::Parser;

/// Write bytes to file.
///
Expand Down Expand Up @@ -47,7 +47,9 @@ pub(crate) fn write_bytes_bz2<W: Write>(
}

/// Set up the stream for reading. Autodetects and decompresses BZ2.
pub(crate) fn create_stream<'b>(dmap_data: &'b mut impl Read) -> Result<Box<dyn Read + 'b>, DmapError> {
pub(crate) fn create_stream<'b>(
dmap_data: &'b mut impl Read,
) -> Result<Box<dyn Read + 'b>, DmapError> {
let (is_bz2, chunk) = detect_bz2(dmap_data)?;
if is_bz2 {
Ok(Box::new(BzDecoder::new(chunk)))
Expand All @@ -57,9 +59,7 @@ pub(crate) fn create_stream<'b>(dmap_data: &'b mut impl Read) -> Result<Box<dyn
}

/// Parses `dmap_data` into discrete chunks, each corresponding to a DMAP record.
pub(crate) fn split_into_slices(
mut dmap_data: impl Read,
) -> Result<Vec<Parser>, DmapError> {
pub(crate) fn split_into_slices(mut dmap_data: impl Read) -> Result<Vec<Parser>, DmapError> {
let mut buffer: Vec<u8> = vec![];
create_stream(&mut dmap_data)?.read_to_end(&mut buffer)?;

Expand Down Expand Up @@ -107,8 +107,8 @@ pub(crate) fn slice_stream_lax(buffer: Vec<u8>) -> (Vec<Parser>, Vec<usize>, Opt

let mut rec_starts = vec![];
while ((rec_start + 2 * i32::size()) as u64) < buffer.len() as u64 {
rec_size = i32::from_le_bytes(buffer[rec_start + 4..rec_start + 8].try_into().unwrap())
as usize; // advance 4 bytes, skipping the "code" field
rec_size =
i32::from_le_bytes(buffer[rec_start + 4..rec_start + 8].try_into().unwrap()) as usize; // advance 4 bytes, skipping the "code" field
rec_end = rec_start + rec_size; // error-checking the size is conducted in Self::parse_record()
if rec_end > buffer.len() || rec_size == 0 {
bad_byte = Some(rec_start);
Expand Down
Loading
Loading