← 返回目录

LZMA 算法 AS3 移植 实现

发布时间: 2011-12-09 00:52:35
浏览量: 11277
标签: 算法, properties, null, function
使用方法如下:源代码打包上传,欢迎下载使用. 源代码下载地址 http://download.csdn.net/detail/aerror/3898251  public static function decode(src:ByteArray) : ByteArray { if (src == null || src.

使用方法如下:
源代码打包上传,欢迎下载使用.

源代码下载地址

 http://download.csdn.net/detail/aerror/3898251

 

        public static function decode(src:ByteArray) : ByteArray
        {
            if (src == null || src.length < 16)
            {
                return null;
            }
			
			var inStream:InputStream = new InputStream(src);
			var propertiesSize:int = 5;
			var properties:Vector.<uint> = new Vector.<uint>(propertiesSize);
			
			if (inStream.readVOL(properties, 0, propertiesSize) != propertiesSize)
				return null;
			var decoder:Decoder = new Decoder();
			if (!decoder.SetDecoderProperties(properties))
				return null;
			var outSize:uint = 0;
			for (var i:int = 0; i < 8; i++)
			{
				var v:int = inStream.read();
				if (v < 0)
					return null;
				outSize |= (v << (8 * i));
			}
			var ret:ByteArray = new ByteArray();
			ret.length = outSize;
			var outStream:OutputStream = new OutputStream(ret);
			if (!decoder.Code(inStream, outStream, outSize))
				return null;
			inStream.close();
			outStream.close();
			ret.position =0;
			return ret;

        }