MCPcopy Index your code
hub / github.com/Recordscript/recordscript / write

Method write

libs/hbb_common/src/fs.rs:387–427  ·  view source on GitHub ↗
(&mut self, block: FileTransferBlock)

Source from the content-addressed store, hash-verified

385 }
386
387 pub async fn write(&mut self, block: FileTransferBlock) -> ResultType<()> {
388 if block.id != self.id {
389 bail!("Wrong id");
390 }
391 let file_num = block.file_num as usize;
392 if file_num >= self.files.len() {
393 bail!("Wrong file number");
394 }
395 if file_num != self.file_num as usize || self.file.is_none() {
396 self.modify_time();
397 if let Some(file) = self.file.as_mut() {
398 file.sync_all().await?;
399 }
400 self.file_num = block.file_num;
401 let entry = &self.files[file_num];
402 let path = self.join(&entry.name);
403 if let Some(p) = path.parent() {
404 std::fs::create_dir_all(p).ok();
405 }
406 let path = format!("{}.download", get_string(&path));
407 self.file = Some(File::create(&path).await?);
408 }
409 if block.compressed {
410 let tmp = decompress(&block.data);
411 self.file
412 .as_mut()
413 .ok_or(anyhow!("file is None"))?
414 .write_all(&tmp)
415 .await?;
416 self.finished_size += tmp.len() as u64;
417 } else {
418 self.file
419 .as_mut()
420 .ok_or(anyhow!("file is None"))?
421 .write_all(&block.data)
422 .await?;
423 self.finished_size += block.data.len() as u64;
424 }
425 self.transferred += block.data.len() as u64;
426 Ok(())
427 }
428
429 #[inline]
430 pub fn join(&self, name: &str) -> PathBuf {

Callers 15

Java_ffi_FFI_initFunction · 0.80
clear_codec_infoFunction · 0.80
set_map_errFunction · 0.80
newMethod · 0.80
mainFunction · 0.80
setMethod · 0.80
update_latencyMethod · 0.80
set_idMethod · 0.80
set_nat_typeMethod · 0.80
set_serialMethod · 0.80
set_key_confirmedMethod · 0.80

Calls 3

decompressFunction · 0.85
joinMethod · 0.80
modify_timeMethod · 0.45

Tested by 1

test_overwrite_settingsFunction · 0.64