Exemplo n.º 1
0
        //外部方法:根据文件名获取文件数据
        //[Benchmark]
        public Byte[] GetFile(string name)
        {
            //先从缓存区查找文件
            if (MyCache.GetInstance().GetCacheFile(name) != null)
            {
                return(MyCache.instance.GetCacheFile(name));
            }

            //根据文件头信息读出文件
            if (!filesDic.ContainsKey(name))
            {
                throw new Exception("文件" + name + "不存在!");
            }
            HeadInfo targetHead = filesDic[name];

            byte[] result = new byte[targetHead.length];
            using (FileStream fs = new FileStream(packPath, FileMode.Open))
            {
                fs.Seek(targetHead.start, SeekOrigin.Begin);
                fs.Read(result, 0, targetHead.length);
            }

            //当前文件进行一次规律判断
            MyCache.GetInstance().RuleDetection(name, result);

            return(result);
        }
Exemplo n.º 2
0
 public static MyCache GetInstance()
 {
     if (instance == null)
     {
         instance = new MyCache();
     }
     return(instance);
 }
Exemplo n.º 3
0
        //外部方法:根据文件名获取文件数据
        public Byte[] GetFile(string name)
        {
            //先从缓存区查找文件
            if (MyCache.GetInstance().GetCacheFile(name) != null)
            {
                return(MyCache.instance.GetCacheFile(name));
            }

            //根据文件头信息读出文件
            HeadInfo targetHead = filesDic[name];

            byte[] result = new byte[targetHead.length];
            Array.Copy(packByte, targetHead.start, result, 0, targetHead.length);

            //当前文件进行一次规律判断
            MyCache.GetInstance().RuleDetection(name, result);

            return(result);
        }