1

コードで JSZip オブジェクトを作成できますが、それを Windows 8 アプリのローカル ストレージに保存するのに問題があります。私が見つけることができる例では、ブラウザーの location.href を設定してダウンロードをトリガーしますが、これは実際にはオプションではありません。

以下に私のコードを含めました。最終的に作成された zip ファイルは無効であり、開くことができません。どんな助けでも大歓迎です。

参考:JSZip

        function _zipTest() {
        var dbFile = null;
        var zipData = null;
        Windows.Storage.StorageFile.getFileFromPathAsync(config.db.path)
            .then(function (file) {
                dbFile = file;
                return Windows.Storage.FileIO.readBufferAsync(file);
            })
            .then(function (buffer) {
                //Read the database file into a byte array and create a new zip file
                zipData = new Uint8Array(buffer.length);
                var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(buffer);
                dataReader.readBytes(zipData);
                dataReader.close();

                var localFolder = Windows.Storage.ApplicationData.current.localFolder;
                return localFolder.createFileAsync(dbFile.displayName.concat('.zip'), Windows.Storage.CreationCollisionOption.replaceExisting)
            })
            .then(function (file) {
                //Write the zip data to the new zip file
                var zip = new JSZip();
                zip.file(dbFile.displayName, zipData);
                var content = zip.generate();

                return Windows.Storage.FileIO.writeTextAsync(file, content);
            });
    }
4

1 に答える 1