Auto merge of #12577 - izgzhen:fm-chunked, r=Manishearth

Chunked ReadFile from file manager

+ Introduce a `ReadFileProgress` sender in the `ReadFile` msg to file manager, and implement the related I/O operations
+ Change `tests/unit/net/test.jpeg` from a 4.8K file to a 39K file to better test the chunked reading (Since one chunk is maximally 8129 Bytes).

r? @Manishearth

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12577)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-07-26 02:42:45 -05:00 committed by GitHub
commit b41bf4f1f3
7 changed files with 163 additions and 57 deletions

View file

@ -16,7 +16,7 @@ use encoding::types::{EncoderTrap, Encoding};
use ipc_channel::ipc;
use net_traits::IpcSend;
use net_traits::blob_url_store::{BlobBuf, get_blob_origin};
use net_traits::filemanager_thread::{FileManagerThreadMsg, SelectedFileId, RelativePos};
use net_traits::filemanager_thread::{FileManagerThreadMsg, SelectedFileId, RelativePos, ReadFileProgress};
use std::cell::Cell;
use std::ops::Index;
use std::path::PathBuf;
@ -286,9 +286,21 @@ fn read_file(global: GlobalRef, id: SelectedFileId) -> Result<Vec<u8>, ()> {
let msg = FileManagerThreadMsg::ReadFile(chan, id, check_url_validity, origin);
let _ = file_manager.send(msg);
match recv.recv().unwrap() {
Ok(blob_buf) => Ok(blob_buf.bytes),
Err(_) => Err(()),
let mut bytes = vec![];
loop {
match recv.recv().unwrap() {
Ok(ReadFileProgress::Meta(mut blob_buf)) => {
bytes.append(&mut blob_buf.bytes);
}
Ok(ReadFileProgress::Partial(mut bytes_in)) => {
bytes.append(&mut bytes_in);
}
Ok(ReadFileProgress::EOF) => {
return Ok(bytes);
}
Err(_) => return Err(()),
}
}
}