Read feature in progress.

This commit is contained in:
AB
2020-06-05 02:28:12 +03:00
parent be7be1da46
commit 6e6bab7e55
2 changed files with 36 additions and 17 deletions

View File

@ -881,25 +881,26 @@ impl MemFS {
} }
counter += 1; counter += 1;
}; };
drop(full_path_mutex); // let inodes = self.inodes.lock().await;
let inodes = self.inodes.lock().await; //
// let inode = inodes.get(op.ino()).ok_or_else(no_entry)?;
let inode = inodes.get(op.ino()).ok_or_else(no_entry)?; // let inode = inode.lock().await;
let inode = inode.lock().await; //
//
// let content = match inode.kind {
let content = match inode.kind { // INodeKind::RegularFile(ref content) => content,
INodeKind::RegularFile(ref content) => content, // _ => return Err(io::Error::from_raw_os_error(libc::EINVAL)),
_ => return Err(io::Error::from_raw_os_error(libc::EINVAL)), // };
}; //
let offset = op.offset() as usize; let offset = op.offset() as usize;
let size = op.size() as usize; let size = op.size() as usize;
drop(full_path_mutex);
let chunk = self.http.read(full_path, size, offset).await.unwrap();
let content = content.get(offset..).unwrap_or(&[]); //let content = content.get(offset..).unwrap_or(&[]);
let content = &content[..std::cmp::min(content.len(), size)]; //let content = &content[..std::cmp::min(content.len(), size)];
Ok(content.to_vec()) Ok(chunk.to_vec())
} }
async fn do_write<R: ?Sized>( async fn do_write<R: ?Sized>(

View File

@ -55,14 +55,13 @@ impl HTTP {
let client = reqwest::Client::builder() let client = reqwest::Client::builder()
.user_agent(APP_USER_AGENT) .user_agent(APP_USER_AGENT)
.default_headers(headers) .default_headers(headers)
// .gzip(true)
.build().unwrap(); .build().unwrap();
Self { Self {
client, client,
server server
} }
} }
pub async fn list(&self, path: PathBuf, ) -> Result<Vec<RemoteEntry>, Error> { pub async fn list(&self, path: PathBuf) -> Result<Vec<RemoteEntry>, Error> {
debug!("Fetching path '{}/{}'", self.server, path.display()); debug!("Fetching path '{}/{}'", self.server, path.display());
let mut client = &self.client; let mut client = &self.client;
let resp = client let resp = client
@ -74,5 +73,24 @@ impl HTTP {
info!("Found {} entries into '{}'", resp.len(), path.display()); info!("Found {} entries into '{}'", resp.len(), path.display());
Ok(resp) Ok(resp)
} }
pub async fn read(&self, path: PathBuf, size: usize, offset: usize) -> Result<Vec<u8>, Error> {
debug!("Reading path '{}/{}'", self.server, path.display());
let mut headers = header::HeaderMap::new();
let range = format!("bytes={}-{}", offset, {offset+size});
headers.insert(header::RANGE, header::HeaderValue::from_str(range.as_str()).unwrap());
let mut client = &self.client;
let resp = client
.get(format!("{}/{}", self.server, path.display()).as_str())
.headers(headers)
.send()
.await?
.bytes()
.await?;
info!("Found {} entries into '{}'", resp.len(), path.display());
Ok(resp.to_vec())
}
} }