aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/blob.rs
diff options
context:
space:
mode:
authorZhen Zhang <izgzhen@gmail.com>2016-05-10 20:23:17 +0800
committerZhen Zhang <izgzhen@gmail.com>2016-05-11 22:35:21 +0800
commit87fec3e026484d84b34cfa989dcbc6173bdcc161 (patch)
tree6808ddc2a491a29369696dc2d335ddfee38bfd3e /components/script/dom/blob.rs
parentf43009333fb919421e584e38af3e8aaa0ff4fd1e (diff)
downloadservo-87fec3e026484d84b34cfa989dcbc6173bdcc161.tar.gz
servo-87fec3e026484d84b34cfa989dcbc6173bdcc161.zip
Implement missing interfaces of File DOM object
Diffstat (limited to 'components/script/dom/blob.rs')
-rw-r--r--components/script/dom/blob.rs35
1 files changed, 18 insertions, 17 deletions
diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs
index 2ef0479ab9b..e0d260b2b78 100644
--- a/components/script/dom/blob.rs
+++ b/components/script/dom/blob.rs
@@ -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()
}
}
}