- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 AIR 应用程序的初始启动时(第一次安装后)获取一个 db zip,然后通过 FZip 解压缩。
在此操作之后,我立即需要从生成的 sqlite db 加载数据,这会失败,因为我似乎无法确定 zip 何时完全解压缩和/或 sqlite 已创建。
有什么建议么?谢谢!
最佳答案
好吧,您在问题中有答案。
我快速浏览了FZip docs并注意到当
zip 文件已加载。
只需扫描 FZipLibrary.as 中的代码有进程下一个() 方法
其中包含一个 while 循环来遍历存档中的文件。您可以将 FILE_PARSED 常量添加到 FZipEvent 并在 while 循环完成后从那里分派(dispatch)此类事件。
我目前无法尝试对此进行测试,但这就是我的意思:
/*
* Copyright (C) 2006 Claus Wahlers and Max Herkender
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
package deng.fzip
{
import deng.fzip.FZipFile;
import flash.events.Event;
/**
* FZip dispatches FZipEvent objects when a file contained in the
* ZIP archive has finished loading and can be accessed. There is
* only one type of FZipEvent: FZipErrorEvent.FILE_LOADED.
*/
public class FZipEvent extends Event
{
/**
* The file that has finished loading.
*/
public var file:FZipFile;
/**
* Defines the value of the type property of a FZipEvent object.
*/
public static const FILE_LOADED:String = "fileLoaded";
/**
* Zip contents were parsed
*/
public static const FILE_PARSED:String = "fileParsed";
/**
* Constructor
*
* @param type The type of the event. Event listeners can
* access this information through the inherited type property.
* There is only one type of FZipEvent:
* FZipEvent.PARSE_ERROR.
*
* @param file The file that has finished loading.
*
* @param bubbles Determines whether the Event object participates
* in the bubbling stage of the event flow. Event listeners can
* access this information through the inherited bubbles property.
*
* @param cancelable Determines whether the Event object can be
* canceled. Event listeners can access this information through
* the inherited cancelable property.
*/
public function FZipEvent(type:String, file:FZipFile = null, bubbles:Boolean = false, cancelable:Boolean = false) {
this.file = file;
super(type, bubbles, cancelable);
}
/**
* Creates a copy of the FZipEvent object and sets the value
* of each property to match that of the original.
*
* @return A new FZipEvent object with property values that
* match those of the original.
*/
override public function clone():Event {
return new FZipEvent(type, file, bubbles, cancelable);
}
}
}
/*
* Copyright (C) 2006 Claus Wahlers and Max Herkender
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
package deng.fzip {
import flash.events.*;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.utils.ByteArray;
/**
* Dispatched when all pending files have been processed.
*
* @eventType flash.events.Event.COMPLETE
*/
[Event(name="complete", type="flash.events.Event")]
/**
* <p>FZipLibrary works with a FZip instance to load files as
* usable instances, like a DisplayObject or BitmapData. Each file
* from a loaded zip is processed based on their file extentions.
* More than one FZip instance can be supplied, and if it is
* currently loading files, then FZipLibrary will wait for incoming
* files before it completes.</p>
*
* <p>Flash's built-in Loader class is used to convert formats, so the
* only formats currently supported are ones that Loader supports.
* As of this writing they are SWF, JPEG, GIF, and PNG.</p>
*
* <p>The following example loads an external zip file, outputs the
* width and height of an image and then loads a sound from a SWF file.</p>
*
* <pre>
* package {
* import flash.events.*;
* import flash.display.BitmapData;
* import deng.fzip.FZip;
* import deng.fzip.FZipLibrary;
*
* public class Example {
* private var lib:FZipLibrary;
*
* public function Example(url:String) {
* lib = new FZipLibrary();
* lib.formatAsBitmapData(".gif");
* lib.formatAsBitmapData(".jpg");
* lib.formatAsBitmapData(".png");
* lib.formatAsDisplayObject(".swf");
* lib.addEventListener(Event.COMPLETE,onLoad);
*
* var zip:FZip = new FZip();
* zip.load(url);
* lib.addZip(zip);
* }
* private function onLoad(evt:Event) {
* var image:BitmapData = lib.getBitmapData("test.png");
* trace("Size: " + image.width + "x" + image.height);
*
* var importedSound:Class = lib.getDefinition("data.swf", "SoundClass") as Class;
* var snd:Sound = new importedSound() as Sound;
* }
* }
* }</pre>
*
* @see http://livedocs.macromedia.com/flex/201/langref/flash/display/Loader.html
*/
public class FZipLibrary extends EventDispatcher {
static private const FORMAT_BITMAPDATA:uint = (1 << 0);
static private const FORMAT_DISPLAYOBJECT:uint = (1 << 1);
private var pendingFiles:Array = [];
private var pendingZips:Array = [];
private var currentState:uint = 0;
private var currentFilename:String;
private var currentZip:FZip;
private var currentLoader:Loader;
private var bitmapDataFormat:RegExp = /[]/;
private var displayObjectFormat:RegExp = /[]/;
private var bitmapDataList:Object = {};
private var displayObjectList:Object = {};
/**
* Constructor
*/
public function FZipLibrary() {
}
/**
* Use this method to add an FZip instance to the processing queue.
* If the FZip instance specified is not active (currently receiving files)
* when it is processed than only the files already loaded will be processed.
*
* @param zip An FZip instance to process
*/
public function addZip(zip:FZip):void {
pendingZips.unshift(zip);
processNext();
}
/**
* Used to indicate a file extension that triggers formatting to BitmapData.
*
* @param ext A file extension (".jpg", ".png", etc)
*/
public function formatAsBitmapData(ext:String):void {
bitmapDataFormat = addExtension(bitmapDataFormat,ext);
}
/**
* Used to indicate a file extension that triggers formatting to DisplayObject.
*
* @param ext A file extension (".swf", ".png", etc)
*/
public function formatAsDisplayObject(ext:String):void {
displayObjectFormat = addExtension(displayObjectFormat,ext);
}
/**
* @private
*/
private function addExtension(original:RegExp,ext:String):RegExp {
return new RegExp(ext.replace(/[^A-Za-z0-9]/,"\\$&")+"$|"+original.source);
}
/**
* Request a file that has been formatted as BitmapData.
* A ReferenceError is thrown if the file does not exist as a
* BitmapData.
*
* @param filename The filename of the BitmapData instance.
*/
public function getBitmapData(filename:String):BitmapData {
if (!bitmapDataList[filename] is BitmapData) {
throw new Error("File \""+filename+"\" was not found as a BitmapData");
}
return bitmapDataList[filename] as BitmapData;
}
/**
* Request a file that has been formatted as a DisplayObject.
* A ReferenceError is thrown if the file does not exist as a
* DisplayObject.
*
* @param filename The filename of the DisplayObject instance.
*/
public function getDisplayObject(filename:String):DisplayObject {
if (!displayObjectList.hasOwnProperty(filename)) {
throw new ReferenceError("File \""+filename+"\" was not found as a DisplayObject");
}
return displayObjectList[filename] as DisplayObject;
}
/**
* Retrieve a definition (like a class) from a SWF file that has
* been formatted as a DisplayObject.
* A ReferenceError is thrown if the file does not exist as a
* DisplayObject, or the definition does not exist.
*
* @param filename The filename of the DisplayObject instance.
*/
public function getDefinition(filename:String,definition:String):Object {
if (!displayObjectList.hasOwnProperty(filename)) {
throw new ReferenceError("File \""+filename+"\" was not found as a DisplayObject, ");
}
var disp:DisplayObject = displayObjectList[filename] as DisplayObject;
try {
return disp.loaderInfo.applicationDomain.getDefinition(definition);
} catch (e:ReferenceError) {
throw new ReferenceError("Definition \""+definition+"\" in file \""+filename+"\" could not be retrieved: "+e.message);
}
return null;
}
/**
* @private
*/
private function processNext(evt:Event = null):void {
while (currentState === 0) {
if (pendingFiles.length > 0) {
var nextFile:FZipFile = pendingFiles.pop();
if (bitmapDataFormat.test(nextFile.filename)) {
currentState |= FORMAT_BITMAPDATA;
}
if (displayObjectFormat.test(nextFile.filename)) {
currentState |= FORMAT_DISPLAYOBJECT;
}
if ((currentState & (FORMAT_BITMAPDATA | FORMAT_DISPLAYOBJECT)) !== 0) {
currentFilename = nextFile.filename;
currentLoader = new Loader();
currentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
currentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderCompleteHandler);
var content:ByteArray = nextFile.content;
content.position = 0;
currentLoader.loadBytes(content);
break;
}
} else if (currentZip == null) {
if (pendingZips.length > 0) {
currentZip = pendingZips.pop();
var i:uint = currentZip.getFileCount();
while (i > 0) {
pendingFiles.push(currentZip.getFileAt(--i));
}
if (currentZip.active) {
currentZip.addEventListener(Event.COMPLETE, zipCompleteHandler);
currentZip.addEventListener(FZipEvent.FILE_LOADED, fileCompleteHandler);
currentZip.addEventListener(FZipErrorEvent.PARSE_ERROR, zipCompleteHandler);
break;
} else {
currentZip = null;
}
} else {
dispatchEvent(new Event(Event.COMPLETE));
break;
}
} else {
break;
}
}
dispatchEvent(new FZipEvent(FZipEvent.FILE_PARSED));
}
/**
* @private
*/
private function loaderCompleteHandler(evt:Event):void {
if ((currentState & FORMAT_BITMAPDATA) === FORMAT_BITMAPDATA) {
if (currentLoader.content is Bitmap && (currentLoader.content as Bitmap).bitmapData is BitmapData) {
var bitmapData:BitmapData = (currentLoader.content as Bitmap).bitmapData
bitmapDataList[currentFilename] = bitmapData.clone();
//trace(currentFilename+" -> BitmapData ("+bitmapData.width+"x"+bitmapData.height+")");
} else if (currentLoader.content is DisplayObject) {
var width:uint = uint(currentLoader.content.width);
var height:uint = uint(currentLoader.content.height);
if (width && height) {
var bitmapData2:BitmapData = new BitmapData(width,height,true,0x00000000);
bitmapData2.draw(currentLoader);
bitmapDataList[currentFilename] = bitmapData2;
//trace(currentFilename+" -> BitmapData ("+bitmapData2.width+"x"+bitmapData2.height+")");
} else {
trace("File \""+currentFilename+"\" could not be converted to BitmapData");
}
} else {
trace("File \""+currentFilename+"\" could not be converted to BitmapData");
}
}
if ((currentState & FORMAT_DISPLAYOBJECT) === FORMAT_DISPLAYOBJECT) {
if (currentLoader.content is DisplayObject) {
//trace(currentFilename+" -> DisplayObject");
displayObjectList[currentFilename] = currentLoader.content;
} else {
currentLoader.unload();
trace("File \""+currentFilename+"\" could not be loaded as a DisplayObject");
}
} else {
currentLoader.unload();
}
currentLoader = null;
currentFilename = "";
currentState &= ~(FORMAT_BITMAPDATA | FORMAT_DISPLAYOBJECT);
processNext();
}
/**
* @private
*/
private function fileCompleteHandler(evt:FZipEvent):void {
pendingFiles.unshift(evt.file);
processNext();
}
/**
* @private
*/
private function zipCompleteHandler(evt:Event):void {
currentZip.removeEventListener(Event.COMPLETE, zipCompleteHandler);
currentZip.removeEventListener(FZipEvent.FILE_LOADED, fileCompleteHandler);
currentZip.removeEventListener(FZipErrorEvent.PARSE_ERROR, zipCompleteHandler);
currentZip = null;
processNext();
}
}
}
关于sqlite - 确定何时解压缩数据库 zip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2651967/
我有这个命令: 7z e -oD:\Data\ODS_Source\* D:\Data\DATA_DROP\Source.zip 这导致 D:\Data\ODS_Source\Source\. 我需要
我正在尝试让 Ionic zip 将 zip 文件内的文件夹提取到指定的根目录中。我的问题是里面的zip文件是“zipfile.zip\some_folder\”。我想将“some_folder”中的
我试图让 Ionic zip 将 zip 文件中的文件夹提取到指定的根目录中。我的问题是里面的 zip 文件是“zipfile.zip\some_folder\”。我想将“some_folder”中的
题目 监听服务器端口,得到题目如下: 源码解析 主函数 主函数中是题目界面的逻辑,对应于用户的选择做出相应的操作,其中需要注意的是选项2,解压操作需要获得root权
我有许多需要分发给用户的zip文件,其中约有130个。每个zip文件都包含许多相似的文本,html,xml和jpg文件。压缩文件总计146兆字节;解压缩后,其内容总计551mb。 我想将所有这些文件以
我正在使用 javascript zip.js图书馆。我到处搜索,但找不到将多个文件添加到 zip 的示例。 这是我的代码,但它生成了一个“损坏的”zip。 var len = results.row
在 C# 中,我使用的是 DotNetZip我有一个名为“innerZip.zip”的 zip,其中包含一些数据,和另一个名为“outerZip.zip”的 zip,其中包含 innerZip。我为什
当我使用 library(xlsx) 中的 write.xlsx 时,控制台中会出现以下内容: Note: zip::zip() is deprecated, please use zip::zipr
如果我因为问“非编程”问题而被拒绝,我不会太惊讶,但也许有人知道...... 我正在使用 WinXP 的内置“发送到压缩(zipped)文件夹”功能压缩我的 subversion 沙箱的内容,并惊讶地
我在 Elixir 中有一个二进制字符串,它由压缩字节组成,我想放气并从中提取“真实数据”: iex(93)> data > 我不确定如何解压缩这些数据。到目前为止,我已经: 浏览了 Official
有没有一种方法可以创建一个 zip 文件并强制它在命令行中包含数据描述符部分? 最佳答案 在 Github ( https://github.com/adamhathcock/sharpcompres
我已经有 PBDT.csj and RDK.csj使用此 ( https://www.blackberry.com/SignedKeys/codesigning.html ) 链接进行代码签名处理后的
我研究了几天,发现我们可以将一个包含一些内容的文件添加到 zip 文件中,然后再次压缩它。然后注释将被添加到 zip 文件中,但我不知道该文件到底是什么,所以任何人都知道向 zip(压缩)文件添加注释
我想知道如何找到 zip 文件的压缩级别。 7z 和 winzip 制作的 Zip 文件具有不同的级别评级,因此我想将其中的一些映射到其他工具中的相应级别。 store level 或 level 0
到目前为止,对于Zip文件的Mime类型,我已经看到: 应用程序/八位字节流 multipart / x-zip 应用程序/ zip 应用程序/ zip压缩的 应用程序/ x-zip压缩的 我想我的问
我已经在 google 上搜索、在 wiki 上搜索并阅读了 ZIP 的 RFC,但找不到有关 ZIP 中使用的确切算法的任何信息。 我找到了有关 ZIP == TAR + GZIP 的信息 但是,我
我有这些自解压 zip 文件,我正试图在 2008/7 机器上远程解压这些文件。但它们是以 .exe 的方式出现的,它需要用户双击并选择提取位置。 在 WinZip 支持网站上,他们说要使用/auto
这是我在这里的第一个问题,请耐心等待。 我的目标是在 C# 中创建一个基本的 .zip 存档。我已经尝试使用 .NET 的内置 GZipStream 类并设法实现了这一点,但是我遇到了一个问题,我无法
能否为压缩文件中的压缩文件创建 java.nio.file.FileSystem? 如果是这样,URI 是什么样的? 如果没有,我想我将不得不退回到使用 ZipInputStream。 我正在尝试递归
我想在 here 安装 scala我很关心下载哪一个:zip 还是 tgz。它们之间有什么区别,用例是什么? 最佳答案 它们是不同的archive formats .使用它们是因为它可以节省带宽并且因
我是一名优秀的程序员,十分优秀!