diff --git a/Cargo.toml b/Cargo.toml index ec3eef6..1914a8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ cannyls = "^0.9" clap = "2" structopt = "^0.2.11" trackable = "^0.2.20" -rustyline = "2" +rustyline = "5" regex = "1" indicatif = "^0.11" rand = "^0.6" diff --git a/src/handle.rs b/src/handle.rs index 9ad79b0..af6b07b 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -4,7 +4,7 @@ use cannyls::lump::{LumpData, LumpId}; use cannyls::nvm::FileNvm; use cannyls::storage::{JournalSnapshot, Storage, StorageBuilder}; use std::fs::{File, OpenOptions}; -use std::io::Seek; +use std::io::{stdout, Seek, Write}; use std::path::Path; use std::str; @@ -156,6 +156,18 @@ impl StorageHandle { } } } + /// keyに対応するlump dataを生バイト列として出力する + pub fn print_as_raw_bytes(&mut self, key: u128) { + let result = track!(self.get_as_bytes(key)).unwrap(); + match result { + Some(bytes) => { + stdout().write_all(&bytes).unwrap(); + } + None => { + println!("no entry for the key {:?}", key); + } + } + } pub fn delete_key(&mut self, key: u128) -> Result { let lump_id = LumpId::new(key); diff --git a/src/main.rs b/src/main.rs index 0eec1ad..59ecc6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,6 +64,11 @@ arg_enum! { // kanils Get --storage=storage_path --key=lumpid GetBytes, + // lusfストレージの指定したkeyを持つ値を「生のバイト列として」取得する + // 存在しないkeyが指定された場合はその旨が出力される + // kanils GetRaw --storage=storage_path --key=lumpid + GetRaw, + // lusfストレージの指定したkeyを削除する // 存在しないkeyが指定された場合はその旨が出力される // kanils Delete --storage=storage_path --key=lumpid @@ -296,7 +301,7 @@ fn main() { let readline = rl.readline(">> "); match readline { Ok(line) => { - rl.add_history_entry(line.as_ref()); + rl.add_history_entry(&line); handle_input(&mut handle, &line); } Err(ReadlineError::Interrupted) => { @@ -324,6 +329,11 @@ fn main() { let lumpid_str: String = opt.lumpid.unwrap(); handle.print_as_bytes(string_to_u128(&lumpid_str)); } + Command::GetRaw => { + let mut handle = StorageHandle::create(&opt.storage_path); + let lumpid_str: String = opt.lumpid.unwrap(); + handle.print_as_raw_bytes(string_to_u128(&lumpid_str)); + } Command::Put => { let mut handle = StorageHandle::create(&opt.storage_path); let lumpid_str: String = opt.lumpid.unwrap();