Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature/get raw #17

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 13 additions & 1 deletion src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<bool, cannyls::Error> {
let lump_id = LumpId::new(key);
Expand Down
12 changes: 11 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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();
Expand Down