Skip to content

Commit

Permalink
Merge pull request #86 from LDeakin/byte_range_suffix
Browse files Browse the repository at this point in the history
Change `ByteRange::FromEnd` to `ByteRange::Suffix`
  • Loading branch information
LDeakin authored Oct 20, 2024
2 parents 6898fe0 + 86e9add commit a7fe185
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ version = "0.2.0"
path = "zarrs_metadata"

[workspace.dependencies.zarrs_storage]
version = "0.2.2"
version = "0.3.0-dev"
path = "zarrs_storage"

[workspace.dependencies.zarrs_filesystem]
Expand Down
3 changes: 2 additions & 1 deletion zarrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ unsafe_cell_slice = "0.2.0"
zarrs_filesystem = { workspace = true, optional = true }
zarrs_metadata = { workspace = true }
zarrs_storage = { workspace = true }
zfp-sys = {version = "0.1.15", features = ["static"], optional = true }
# zfp-sys is pinned to 0.1.15 to mainain 1.76 MSRV
zfp-sys = {version = "=0.1.15", features = ["static"], optional = true }
zstd = { version = "0.13.1", features = ["zstdmt"], optional = true }

[dependencies.num-complex]
Expand Down
2 changes: 1 addition & 1 deletion zarrs/src/array/codec/array_to_bytes/sharding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn get_index_byte_range(
.map_err(|e| CodecError::Other(e.to_string()))?;
Ok(match index_location {
ShardingIndexLocation::Start => ByteRange::FromStart(0, Some(index_encoded_size)),
ShardingIndexLocation::End => ByteRange::FromEnd(0, Some(index_encoded_size)),
ShardingIndexLocation::End => ByteRange::Suffix(index_encoded_size),
})
}

Expand Down
14 changes: 4 additions & 10 deletions zarrs/src/array/codec/byte_interval_partial_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ impl BytesPartialDecoderTraits for ByteIntervalPartialDecoder {
ByteRange::FromStart(offset, Some(length)) => {
ByteRange::FromStart(self.byte_offset + offset, Some(*length))
}
ByteRange::FromEnd(offset, None) => {
ByteRange::FromStart(self.byte_offset, Some(self.byte_length - *offset))
}
ByteRange::FromEnd(offset, Some(length)) => ByteRange::FromEnd(
self.byte_offset + self.byte_length - offset - *length,
ByteRange::Suffix(length) => ByteRange::FromStart(
self.byte_offset + self.byte_length - *length,
Some(*length),
),
})
Expand Down Expand Up @@ -105,11 +102,8 @@ impl AsyncBytesPartialDecoderTraits for AsyncByteIntervalPartialDecoder {
ByteRange::FromStart(offset, Some(length)) => {
ByteRange::FromStart(self.byte_offset + offset, Some(*length))
}
ByteRange::FromEnd(offset, None) => {
ByteRange::FromStart(self.byte_offset, Some(self.byte_length - *offset))
}
ByteRange::FromEnd(offset, Some(length)) => ByteRange::FromEnd(
self.byte_offset + self.byte_length - offset - *length,
ByteRange::Suffix(length) => ByteRange::FromStart(
self.byte_offset + self.byte_length - *length,
Some(*length),
),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,10 @@ impl BytesPartialDecoderTraits for Crc32cPartialDecoder<'_> {
let length = bytes.len() - CHECKSUM_SIZE;
Cow::Owned(bytes[..length].to_vec())
}
ByteRange::FromEnd(offset, _) => {
if *offset < CHECKSUM_SIZE as u64 {
let length = bytes.len() as u64 - (CHECKSUM_SIZE as u64 - offset);
let length = usize::try_from(length).unwrap();
Cow::Owned(bytes[..length].to_vec())
} else {
bytes
}
ByteRange::Suffix(_) => {
let length = bytes.len() as u64 - (CHECKSUM_SIZE as u64);
let length = usize::try_from(length).unwrap();
Cow::Owned(bytes[..length].to_vec())
}
};
output.push(bytes);
Expand Down Expand Up @@ -101,14 +97,10 @@ impl AsyncBytesPartialDecoderTraits for AsyncCrc32cPartialDecoder {
let length = bytes.len() - CHECKSUM_SIZE;
Cow::Owned(bytes[..length].to_vec())
}
ByteRange::FromEnd(offset, _) => {
if *offset < CHECKSUM_SIZE as u64 {
let length = bytes.len() as u64 - (CHECKSUM_SIZE as u64 - offset);
let length = usize::try_from(length).unwrap();
Cow::Owned(bytes[..length].to_vec())
} else {
bytes
}
ByteRange::Suffix(_) => {
let length = bytes.len() as u64 - (CHECKSUM_SIZE as u64);
let length = usize::try_from(length).unwrap();
Cow::Owned(bytes[..length].to_vec())
}
};
output.push(bytes);
Expand Down
3 changes: 3 additions & 0 deletions zarrs_filesystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Bump `zarrs_storage` to 0.3.0-dev

## [0.1.0] - 2024-09-15

### Added
Expand Down
9 changes: 4 additions & 5 deletions zarrs_filesystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,19 @@ impl ReadableStorageTraits for FilesystemStore {
// Seek
match byte_range {
ByteRange::FromStart(offset, _) => file.seek(SeekFrom::Start(*offset)),
ByteRange::FromEnd(_, None) => file.seek(SeekFrom::Start(0u64)),
ByteRange::FromEnd(offset, Some(length)) => {
file.seek(SeekFrom::End(-(i64::try_from(*offset + *length).unwrap())))
ByteRange::Suffix(length) => {
file.seek(SeekFrom::End(-(i64::try_from(*length).unwrap())))
}
}?;

// Read
match byte_range {
ByteRange::FromStart(_, None) | ByteRange::FromEnd(_, None) => {
ByteRange::FromStart(_, None) => {
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
buffer
}
ByteRange::FromStart(_, Some(length)) | ByteRange::FromEnd(_, Some(length)) => {
ByteRange::FromStart(_, Some(length)) | ByteRange::Suffix(length) => {
let length = usize::try_from(*length).unwrap();
let mut buffer = vec![0; length];
file.read_exact(&mut buffer)?;
Expand Down
3 changes: 3 additions & 0 deletions zarrs_http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Bump `zarrs_storage` to 0.3.0-dev

## [0.1.0] - 2024-09-15

### Added
Expand Down
3 changes: 3 additions & 0 deletions zarrs_object_store/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Bump `zarrs_storage` to 0.3.0-dev

## [0.2.1] - 2024-09-23

### Added
Expand Down
3 changes: 3 additions & 0 deletions zarrs_opendal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- Bump `zarrs_storage` to 0.3.0-dev

## [0.3.1] - 2024-09-23

### Added
Expand Down
7 changes: 7 additions & 0 deletions zarrs_storage/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add `ByteRange::new` and `From` for `RangeBounds<u64>`

### Changed
- Bump `unsafe_cell_slice` to 0.2.0
- **Breaking**: Change `ByteRange::FromEnd` to `ByteRange::Suffix`

### Removed
- **Breaking**: Remove `ByteRange::offset()`

## [0.2.2] - 2024-10-17

Expand Down
2 changes: 1 addition & 1 deletion zarrs_storage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zarrs_storage"
version = "0.2.2"
version = "0.3.0-dev"
authors = ["Lachlan Deakin <[email protected]>"]
edition = "2021"
rust-version = "1.76"
Expand Down
Loading

0 comments on commit a7fe185

Please sign in to comment.