Repository: flex-asjs Updated Branches: refs/heads/develop 7b96ec3b8 -> f6526b7e4
Added optional bytes to BinaryData constructor Added setter for length Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/f6526b7e Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/f6526b7e Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/f6526b7e Branch: refs/heads/develop Commit: f6526b7e436533e92d18c0c73c7e49ed0267775e Parents: 7b96ec3 Author: Harbs <[email protected]> Authored: Sun Jul 3 10:36:56 2016 +0300 Committer: Harbs <[email protected]> Committed: Sun Jul 3 10:36:56 2016 +0300 ---------------------------------------------------------------------- .../flex/org/apache/flex/utils/BinaryData.as | 57 ++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/f6526b7e/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as index 99479da..db7f383 100644 --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as @@ -37,15 +37,39 @@ COMPILE::SWF public class BinaryData { /** - * Constructor. + * Constructor. The constructor takes an optional bytes argument. + * In Flash this should be a ByteArray. In JS this should be an ArrayBuffer * * @langversion 3.0 * @playerversion Flash 10.2 * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public function BinaryData() + public function BinaryData(bytes:Object = null) { + COMPILE::SWF + { + if(bytes) + { + if(!(bytes is ByteArray)) + throw new Error("BinaryData expects an ByteArray in the constructor"); + ba = bytes as ByteArray; + } + else + ba = new ByteArray(); + } + + COMPILE::JS + { + if(bytes) + { + if(!(bytes is ArrayBuffer)) + throw new Error("BinaryData expects an ArrayBuffer in the constructor"); + ba = bytes as ArrayBuffer; + } + else + ba = new ArrayBuffer(0); + } } @@ -291,7 +315,34 @@ public class BinaryData return ba.byteLength; } } - + + public function set length(value:int):void + { + COMPILE::SWF + { + ba.length = value; + } + + COMPILE::JS + { + setBufferSize(value); + } + + } + + COMPILE::JS + private function setBufferSize(newSize):void + { + var n:int = ba.byteLength; + var newBuffer:ArrayBuffer = new ArrayBuffer(newSize); + var newView:Uint8Array = new Uint8Array(newBuffer, 0, n); + var view:Uint8Array = new Uint8Array(ba, 0, n); + for (var i:int = 0; i < n; i++) + { + newView[i] = view[i]; + } + ba = newBuffer; + } /** * The total number of bytes remaining to be read. *
