Skip to content

Commit

Permalink
Make stream buffer size configurable, and have a larger default
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Nov 5, 2024
1 parent a1fedf0 commit 92057e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ pub struct App {
/// A quit was requested
pub quit_requested: bool,
pub plugins: Vec<PluginContainer>,
/// Size of the buffer used for streaming reads
pub stream_buffer_size: usize,
}

const DEFAULT_STREAM_BUFFER_SIZE: usize = 65_536;

impl App {
pub(crate) fn new(
mut args: Args,
Expand Down Expand Up @@ -107,6 +111,7 @@ impl App {
backend_cmd: Default::default(),
quit_requested: false,
plugins: Vec::new(),
stream_buffer_size: args.src.stream_buffer_size.unwrap_or(DEFAULT_STREAM_BUFFER_SIZE),
};
for path in args.load_plugin {
this.plugins.push(unsafe { PluginContainer::new(path)? });
Expand Down Expand Up @@ -378,6 +383,7 @@ impl App {
take: None,
read_only,
stream: false,
stream_buffer_size: None,
},
None,
msg,
Expand Down Expand Up @@ -475,8 +481,8 @@ impl App {
let (tx, rx) = std::sync::mpsc::channel();
let mut src_clone = src.provider.clone();
self.stream_read_recv = Some(rx);
let buffer_size = self.stream_buffer_size;
thread::spawn(move || {
let buffer_size = 1024;
let mut buf = vec![0; buffer_size];
let result: anyhow::Result<()> = try {
let amount = src_clone.read(&mut buf)?;
Expand Down Expand Up @@ -1013,6 +1019,7 @@ fn load_proc_memory_linux(
take: Some(size),
read_only: !is_write,
stream: false,
stream_buffer_size: None,
},
None,
msg,
Expand Down
6 changes: 5 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ pub struct SourceArgs {
/// Open file as read-only, without writing privileges
#[arg(long)]
pub read_only: bool,
#[arg(long)]
/// Specify source as a streaming source (for example, standard streams).
/// Sets read-only attribute.
#[arg(long)]
pub stream: bool,
/// The buffer size in bytes to use for reading when streaming
#[arg(long)]
#[serde(default)]
pub stream_buffer_size: Option<usize>,
}
1 change: 1 addition & 0 deletions src/gui/file_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl FileOps {
take: None,
read_only: false,
stream: false,
stream_buffer_size: None,
});
};
msg_if_fail(result, "Failed to save as", msg);
Expand Down

0 comments on commit 92057e6

Please sign in to comment.