@@ -71,12 +71,13 @@ fn stackerdb_session(host: &str, contract: QualifiedContractIdentifier) -> Stack
71
71
/// Write the chunk to stdout
72
72
fn write_chunk_to_stdout ( chunk_opt : Option < Vec < u8 > > ) {
73
73
if let Some ( chunk) = chunk_opt. as_ref ( ) {
74
- let sanitized_chunk = sanitize_chunk ( chunk) ;
75
- let bytes = io:: stdout ( ) . write ( & sanitized_chunk) . unwrap ( ) ;
76
- if bytes < sanitized_chunk. len ( ) {
74
+ let hexed_string = to_hex ( chunk) ;
75
+ let hexed_chunk = hexed_string. as_bytes ( ) ;
76
+ let bytes = io:: stdout ( ) . write ( & hexed_chunk) . unwrap ( ) ;
77
+ if bytes < hexed_chunk. len ( ) {
77
78
print ! (
78
79
"Failed to write complete chunk to stdout. Missing {} bytes" ,
79
- sanitized_chunk . len( ) - bytes
80
+ hexed_chunk . len( ) - bytes
80
81
) ;
81
82
}
82
83
}
@@ -178,8 +179,8 @@ fn handle_list_chunks(args: StackerDBArgs) {
178
179
let mut session = stackerdb_session ( & args. host , args. contract ) ;
179
180
let chunk_list = session. list_chunks ( ) . unwrap ( ) ;
180
181
let chunk_list_json = serde_json:: to_string ( & chunk_list) . unwrap ( ) ;
181
- let sanitized_output = sanitize_json_output ( & chunk_list_json) ;
182
- println ! ( "{}" , sanitized_output ) ;
182
+ let hexed_json = to_hex ( chunk_list_json. as_bytes ( ) ) ;
183
+ println ! ( "{}" , hexed_json ) ;
183
184
}
184
185
185
186
fn handle_put_chunk ( args : PutChunkArgs ) {
@@ -369,33 +370,6 @@ fn write_file(dir: &Path, filename: &str, contents: &str) {
369
370
println ! ( "Created file: {}" , filename) ;
370
371
}
371
372
372
- /// Helper function for sanitizing StackerDB chunks to ensure safe terminal output
373
- fn sanitize_chunk ( data : & [ u8 ] ) -> Vec < u8 > {
374
- let mut result = Vec :: new ( ) ;
375
- let mut i = 0 ;
376
- while i < data. len ( ) {
377
- // skipping ANSI escape sequence
378
- if i + 1 < data. len ( ) && data[ i] == 0x1B && data[ i + 1 ] == b'[' {
379
- i += 2 ;
380
- while i < data. len ( ) && !( data[ i] >= 0x40 && data[ i] <= 0x7E ) {
381
- i += 1 ;
382
- }
383
- i += 1 ;
384
- } else {
385
- result. push ( data[ i] ) ;
386
- i += 1 ;
387
- }
388
- }
389
- result
390
- }
391
-
392
- /// Helper function for sanitizing JSON String to ensure safe terminal output
393
- fn sanitize_json_output ( input : & str ) -> String {
394
- // regex to remove ANSI escape sequences
395
- let re = regex:: Regex :: new ( r"(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]" ) . unwrap ( ) ;
396
- re. replace_all ( input, "" ) . to_string ( )
397
- }
398
-
399
373
fn main ( ) {
400
374
let cli = Cli :: parse ( ) ;
401
375
0 commit comments