Browse files

Correct FileLength in header. Fixes #1.

  • Loading branch information...
1 parent bcc5d9c commit 33a1a41f72722574e49af09d7667ebf8782b127e @krilnon committed Jan 27, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 swf/SWFWriter.as
View
16 swf/SWFWriter.as
@@ -28,28 +28,34 @@ package swf {
private function _write():void {
_writeHeader()
var compressedBytes:ByteArray = new ByteArray
- compressedBytes.endian = Endian.BIG_ENDIAN
+ compressedBytes.endian = Endian.LITTLE_ENDIAN // was BIG, unsure why
ByteUtils.writeRect(compressedBytes, _swf.frameSize)
- compressedBytes.writeShort(_swf.frameRate) // FIXME: SWFReader only reads a single byte, but the spec says it's a U16
+ compressedBytes.position++
+ compressedBytes.writeByte(_swf.frameRate) // FIXME: SWFReader only reads a single byte, but the spec says it's a U16
compressedBytes.writeShort(_swf.frameCount)
var tagBytes:ByteArray = _writeTags()
compressedBytes.writeBytes(tagBytes)
+ /*
+ Fixes #1. SWF format:
+ "If this is a compressed SWF file (CWS signature), the FileLength field indicates the total length
+ of the file after decompression, and thus generally does not match the file size."
+ */
+ var fileLength:int = compressedBytes.length + _bytes.length
if(_swf.compressed){
- trace('is compressed')
// ZLIB compress the bytes past the header
compressedBytes.compress()
}
_bytes.writeBytes(compressedBytes) // todo: check 2nd arg accuracy
// go back and write the real file length
_bytes.position = 4
- _bytes.writeUnsignedInt(_bytes.length)
+ _bytes.writeUnsignedInt(fileLength)
_bytes.position = _bytes.length
}
private function _writeHeader():void {
- // signature FWS or CWS
+ // signature CWS or FWS
_bytes.writeByte(_swf.compressed ? 0x43 : 0x46)
_bytes.writeByte(0x57)
_bytes.writeByte(0x53)

0 comments on commit 33a1a41

Please sign in to comment.