mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Fixes related to file input and File API
This commit is contained in:
parent
e65009f317
commit
e0f3cdafe1
3 changed files with 15 additions and 6 deletions
|
@ -66,6 +66,10 @@ impl DataSlice {
|
||||||
&self.bytes[self.bytes_start..self.bytes_end]
|
&self.bytes[self.bytes_start..self.bytes_end]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_all_bytes(&self) -> Arc<Vec<u8>> {
|
||||||
|
self.bytes.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn size(&self) -> u64 {
|
pub fn size(&self) -> u64 {
|
||||||
(self.bytes_end as u64) - (self.bytes_start as u64)
|
(self.bytes_end as u64) - (self.bytes_start as u64)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,15 @@ pub struct File {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
fn new_inherited(_file_bits: &Blob, name: DOMString) -> File {
|
fn new_inherited(file_bits: &Blob, name: DOMString) -> File {
|
||||||
|
// TODO: FilePropertyBag
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
bytes.extend_from_slice(file_bits.get_data().get_all_bytes().as_slice());
|
||||||
|
|
||||||
File {
|
File {
|
||||||
//TODO: get type from the underlying filesystem instead of "".to_string()
|
blob: Blob::new_inherited(Arc::new(bytes), None, None, ""),
|
||||||
blob: Blob::new_inherited(Arc::new(Vec::new()), None, None, ""),
|
|
||||||
name: name,
|
name: name,
|
||||||
}
|
}
|
||||||
// XXXManishearth Once Blob is able to store data
|
|
||||||
// the relevant subfields of file_bits should be copied over
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(global: GlobalRef, file_bits: &Blob, name: DOMString) -> Root<File> {
|
pub fn new(global: GlobalRef, file_bits: &Blob, name: DOMString) -> Root<File> {
|
||||||
|
|
|
@ -40,7 +40,11 @@ impl FileListMethods for FileList {
|
||||||
|
|
||||||
// https://w3c.github.io/FileAPI/#dfn-item
|
// https://w3c.github.io/FileAPI/#dfn-item
|
||||||
fn Item(&self, index: u32) -> Option<Root<File>> {
|
fn Item(&self, index: u32) -> Option<Root<File>> {
|
||||||
|
if (index as usize) < self.list.len() {
|
||||||
Some(Root::from_ref(&*(self.list[index as usize])))
|
Some(Root::from_ref(&*(self.list[index as usize])))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check-tidy: no specs after this line
|
// check-tidy: no specs after this line
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue