avm2: `bytesLoaded` etc reports the compressed file length, not the uncompressed length

This commit is contained in:
David Wendt 2021-03-20 22:33:31 -04:00 committed by kmeisthax
parent d0ad894f70
commit 2a01260f52
2 changed files with 12 additions and 1 deletions

View File

@ -94,7 +94,7 @@ pub fn bytes_total<'gc>(
if let Some(loader_stream) = this.as_loader_stream() {
match &*loader_stream {
LoaderStream::SWF(movie, _) => {
return Ok(movie.data().len().into());
return Ok(movie.compressed_length().into());
}
}
}

View File

@ -28,6 +28,9 @@ pub struct SwfMovie {
/// The suggest encoding for this SWF.
encoding: &'static swf::Encoding,
/// The compressed length of the entire datastream
compressed_length: usize,
}
impl SwfMovie {
@ -46,6 +49,7 @@ impl SwfMovie {
url: None,
parameters: PropertyMap::new(),
encoding: swf::UTF_8,
compressed_length: 0,
}
}
@ -61,6 +65,7 @@ impl SwfMovie {
url: source.url.clone(),
parameters: source.parameters.clone(),
encoding: source.encoding,
compressed_length: source.compressed_length,
}
}
@ -78,6 +83,7 @@ impl SwfMovie {
/// Construct a movie based on the contents of the SWF datastream.
pub fn from_data(swf_data: &[u8], url: Option<String>) -> Result<Self, Error> {
let compressed_length = swf_data.len();
let swf_buf = swf::read::decompress_swf(swf_data)?;
let encoding = swf::SwfStr::encoding_for_version(swf_buf.header.version);
Ok(Self {
@ -86,6 +92,7 @@ impl SwfMovie {
url,
parameters: PropertyMap::new(),
encoding,
compressed_length,
})
}
@ -130,6 +137,10 @@ impl SwfMovie {
pub fn parameters_mut(&mut self) -> &mut PropertyMap<String> {
&mut self.parameters
}
pub fn compressed_length(&self) -> usize {
self.compressed_length
}
}
/// A shared-ownership reference to some portion of an SWF datastream.