• laya zip更新方案


    1.将要打包的的资源和layaairfiles.txt文件一起打成zip.

    2.预加载阶段,先将zip包通过downfile下载并解压到缓存目录.

    3.设置baseurl,开始预加载所有资源.

    4.下面为node.js编写的自动生成layaairfiles.txt的脚本

    var fs = require("fs");
    
    var cacheData = "";
    var tmp = {};
    var totalSize = 0;
    var nowTime = Date.now();
    var BaseUrl = "https://0.0.3/";
    var BasePath = "./bin/";
    var fileList = fs.readdirSync(BasePath);
    tmp["fileUsedSize"] = totalSize;
    for(var i=0;i<fileList.length;i++){
        var file = fileList[i];
        var stats = fs.statSync(BasePath+file);
        if(stats.isDirectory()){
            readFile(BasePath+file+"/",file+"/");
        }else{
            totalSize += stats.size;
            tmp[BaseUrl+file] = {};
            var data = tmp[BaseUrl+file];
            data["md5"] = prePath+file;
            data["readyUrl"] = BaseUrl+file;
            data["size"] = stats.size;
            data["times"] = nowTime;
            var arr = file.split('.');
            if(arr[1] == "atlas"){
                data["encoding"] = "utf8";
            }else{
                data["encoding"] = "";
            }
        }
    }
    tmp["fileUsedSize"] = totalSize;
    var str = JSON.stringify(tmp);
    fs.writeFileSync('./layaairfiles.txt',str);
    
    function readFile(readurl,prePath){
        var fileList = fs.readdirSync(readurl);
        for(var i=0;i<fileList.length;i++){
            var file = fileList[i];
            var stats = fs.statSync(readurl+file);
            if(stats.isDirectory()){
                readFile(readurl+"/"+file+"/",prePath+file+"/");
            }else{
                totalSize += stats.size;
                tmp[BaseUrl+prePath+file] = {};
                var data = tmp[BaseUrl+prePath+file];
                data["md5"] = prePath+file;
                data["readyUrl"] = BaseUrl+prePath+file;
                data["size"] = stats.size;
                data["times"] = nowTime;
                var arr = file.split('.');
                if(arr[1] == "atlas"){
                    data["encoding"] = "utf8";
                }else{
                    data["encoding"] = "";
                }
            }
        }
    }

    5.将下载下来的zip文件解压到缓存目录

    Laya.MiniAdpter.removeAll();
    wx.getFileSystemManager().unzip({
        zipFilePath: res.tempFilePath,
        targetPath: laya.wx.mini.MiniFileMgr.fileNativeDir,
        success: () => {
            this.unzipSuccess();
        },
        fail: (res) => {
            this.unzipFail(res);
        }
    });

  • 相关阅读:
    71)PHP,使用cookie的语法问题
    70)PHP,cookie的安全传输和HTTPonly
    69)PHP,cookie的有效域
    68)PHP,cookie的详细属性和有效期
    C#中的internal关键字
    C# 中如何将一个类文件(XX.CS)封装成.dll文件
    c# 委托和事件(总结篇)
    c#事件实例三
    c#事件实例二
    c#事件实例一
  • 原文地址:https://www.cnblogs.com/wsswlyy/p/10973653.html
Copyright © 2020-2023  润新知