@@ -8,32 +8,32 @@ fn decompress_blosc(compressed_data: &[u8]) -> Result<Vec<u8>, String> {
88 let mut nbytes = 0usize ;
99 let mut cbytes = 0usize ;
1010 let mut blocksize = 0usize ;
11-
11+
1212 blosc_sys:: blosc_cbuffer_sizes (
1313 compressed_data. as_ptr ( ) as * const std:: ffi:: c_void ,
1414 & mut nbytes as * mut usize ,
1515 & mut cbytes as * mut usize ,
1616 & mut blocksize as * mut usize ,
1717 ) ;
18-
18+
1919 if nbytes == 0 {
2020 return Err ( "Invalid compressed data" . to_string ( ) ) ;
2121 }
22-
22+
2323 // Allocate output buffer
2424 let mut decompressed = vec ! [ 0u8 ; nbytes] ;
25-
25+
2626 // Decompress
2727 let result = blosc_sys:: blosc_decompress (
2828 compressed_data. as_ptr ( ) as * const std:: ffi:: c_void ,
2929 decompressed. as_mut_ptr ( ) as * mut std:: ffi:: c_void ,
3030 nbytes,
3131 ) ;
32-
32+
3333 if result < 0 {
3434 return Err ( format ! ( "Blosc decompression failed with code: {}" , result) ) ;
3535 }
36-
36+
3737 decompressed. truncate ( result as usize ) ;
3838 Ok ( decompressed)
3939 }
@@ -43,18 +43,18 @@ fn print_hexdump(data: &[u8], offset: usize, chunk_name: &str) {
4343 println ! ( "=== {} ===" , chunk_name) ;
4444 for ( i, chunk) in data. chunks ( 16 ) . enumerate ( ) {
4545 let addr = offset + i * 16 ;
46-
46+
4747 // Print address
4848 print ! ( "{:08x} " , addr) ;
49-
49+
5050 // Print hex bytes
5151 for ( j, & byte) in chunk. iter ( ) . enumerate ( ) {
5252 if j == 8 {
5353 print ! ( " " ) ; // Extra space in the middle
5454 }
5555 print ! ( "{:02x} " , byte) ;
5656 }
57-
57+
5858 // Pad if chunk is less than 16 bytes
5959 if chunk. len ( ) < 16 {
6060 for j in chunk. len ( ) ..16 {
@@ -64,7 +64,7 @@ fn print_hexdump(data: &[u8], offset: usize, chunk_name: &str) {
6464 print ! ( " " ) ;
6565 }
6666 }
67-
67+
6868 // Print ASCII representation
6969 print ! ( " |" ) ;
7070 for & byte in chunk {
@@ -81,38 +81,38 @@ fn print_hexdump(data: &[u8], offset: usize, chunk_name: &str) {
8181
8282fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
8383 let args: Vec < String > = env:: args ( ) . collect ( ) ;
84-
84+
8585 if args. len ( ) != 2 {
8686 eprintln ! ( "Usage: {} <zarr_array_path>" , args[ 0 ] ) ;
8787 eprintln ! ( "Example: {} /path/to/zarr/array" , args[ 0 ] ) ;
8888 std:: process:: exit ( 1 ) ;
8989 }
90-
90+
9191 let zarr_path = Path :: new ( & args[ 1 ] ) ;
92-
92+
9393 // Verify the path exists
9494 if !zarr_path. exists ( ) {
9595 eprintln ! ( "Error: Path '{}' does not exist" , zarr_path. display( ) ) ;
9696 std:: process:: exit ( 1 ) ;
9797 }
98-
98+
9999 println ! ( "Reading Zarr array from: {}" , zarr_path. display( ) ) ;
100100 println ! ( "========================================" ) ;
101-
101+
102102 // Read zarr.json metadata
103103 let zarr_json_path = zarr_path. join ( "zarr.json" ) ;
104104 if !zarr_json_path. exists ( ) {
105105 eprintln ! ( "Error: zarr.json not found in {}" , zarr_path. display( ) ) ;
106106 std:: process:: exit ( 1 ) ;
107107 }
108-
108+
109109 let metadata_content = fs:: read_to_string ( & zarr_json_path) ?;
110110 let metadata: serde_json:: Value = serde_json:: from_str ( & metadata_content) ?;
111-
111+
112112 // Extract information from metadata
113113 let shape = metadata[ "shape" ] . as_array ( ) . unwrap ( ) ;
114114 let chunk_shape = metadata[ "chunk_grid" ] [ "configuration" ] [ "chunk_shape" ] . as_array ( ) . unwrap ( ) ;
115-
115+
116116 println ! ( "Array shape: {:?}" , shape) ;
117117 println ! ( "Chunk shape: {:?}" , chunk_shape) ;
118118 println ! ( "Data type: {}" , metadata[ "data_type" ] [ "name" ] ) ;
@@ -122,42 +122,42 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
122122 }
123123 }
124124 println ! ( ) ;
125-
125+
126126 // Calculate expected chunks based on the metadata we know:
127127 // Shape: [345, 188], Chunk shape: [128, 128]
128128 // This means we have ceil(345/128) = 3 chunks in dimension 0
129129 // and ceil(188/128) = 2 chunks in dimension 1
130130 // So we expect chunks: c/0/0, c/0/1, c/1/0, c/1/1, c/2/0, c/2/1
131-
131+
132132 let mut chunk_files = Vec :: new ( ) ;
133-
133+
134134 // Find all chunk files by walking the directory
135135 for entry in WalkDir :: new ( zarr_path) {
136136 let entry = entry?;
137137 let path = entry. path ( ) ;
138-
138+
139139 // Look for chunk files (they start with 'c/' in Zarr v3)
140140 if path. is_file ( ) {
141141 let relative_path = path. strip_prefix ( zarr_path) ?;
142142 let path_str = relative_path. to_string_lossy ( ) ;
143-
143+
144144 if path_str. starts_with ( "c/" ) {
145145 chunk_files. push ( ( path. to_path_buf ( ) , path_str. to_string ( ) ) ) ;
146146 }
147147 }
148148 }
149-
149+
150150 // Sort chunk files for consistent ordering
151151 chunk_files. sort_by ( |a, b| a. 1 . cmp ( & b. 1 ) ) ;
152-
152+
153153 println ! ( "Found {} chunk files:" , chunk_files. len( ) ) ;
154154 for ( _, chunk_name) in & chunk_files {
155155 println ! ( " {}" , chunk_name) ;
156156 }
157157 println ! ( ) ;
158-
158+
159159 let mut total_offset = 0 ;
160-
160+
161161 // Read, decompress, and hexdump each chunk file
162162 for ( chunk_path, chunk_name) in chunk_files {
163163 match fs:: read ( & chunk_path) {
@@ -168,7 +168,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
168168 println ! ( ) ;
169169 } else {
170170 println ! ( "Compressed size: {} bytes" , compressed_data. len( ) ) ;
171-
171+
172172 // Decompress the Blosc-compressed data using blosc-sys directly
173173 match decompress_blosc ( & compressed_data) {
174174 Ok ( decompressed_data) => {
@@ -190,11 +190,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
190190 }
191191 }
192192 }
193-
193+
194194 println ! ( "Total decompressed bytes processed: {}" , total_offset) ;
195195 println ! ( ) ;
196196 println ! ( "Note: This shows the decompressed array data as it would appear in memory." ) ;
197197 println ! ( "Each element is 240 bytes (raw_bytes with length_bytes: 240)." ) ;
198-
198+
199199 Ok ( ( ) )
200200}
0 commit comments