mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement missing interfaces of File DOM object
This commit is contained in:
parent
f43009333f
commit
87fec3e026
8 changed files with 71 additions and 141 deletions
|
@ -119,23 +119,11 @@ impl Blob {
|
|||
// TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView
|
||||
let bytes: Vec<u8> = match blobParts {
|
||||
None => Vec::new(),
|
||||
Some(blobs) => {
|
||||
blobs.iter().flat_map(|bPart| {
|
||||
match bPart {
|
||||
&BlobOrString::String(ref s) => {
|
||||
UTF_8.encode(s, EncoderTrap::Replace).unwrap()
|
||||
},
|
||||
&BlobOrString::Blob(ref b) => {
|
||||
b.get_data().get_bytes().to_vec()
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
Some(blobparts) => blob_parts_to_bytes(blobparts),
|
||||
};
|
||||
|
||||
let slice = DataSlice::new(Arc::new(bytes), None, None);
|
||||
Ok(Blob::new(global, slice, blobPropertyBag.get_typestring()))
|
||||
Ok(Blob::new(global, slice, &blobPropertyBag.get_typestring()))
|
||||
}
|
||||
|
||||
pub fn get_data(&self) -> &DataSlice {
|
||||
|
@ -143,6 +131,19 @@ impl Blob {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn blob_parts_to_bytes(blobparts: Vec<BlobOrString>) -> Vec<u8> {
|
||||
blobparts.iter().flat_map(|blobpart| {
|
||||
match blobpart {
|
||||
&BlobOrString::String(ref s) => {
|
||||
UTF_8.encode(s, EncoderTrap::Replace).unwrap()
|
||||
},
|
||||
&BlobOrString::Blob(ref b) => {
|
||||
b.get_data().get_bytes().to_vec()
|
||||
},
|
||||
}
|
||||
}).collect::<Vec<u8>>()
|
||||
}
|
||||
|
||||
impl BlobMethods for Blob {
|
||||
// https://w3c.github.io/FileAPI/#dfn-size
|
||||
fn Size(&self) -> u64 {
|
||||
|
@ -199,11 +200,11 @@ impl BlobMethods for Blob {
|
|||
|
||||
|
||||
impl BlobBinding::BlobPropertyBag {
|
||||
pub fn get_typestring(&self) -> &str {
|
||||
pub fn get_typestring(&self) -> String {
|
||||
if is_ascii_printable(&self.type_) {
|
||||
&*self.type_
|
||||
self.type_.to_lowercase()
|
||||
} else {
|
||||
""
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue