mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Uint8Array return type and create Zlib_CompressFiles
This commit is contained in:
@ -37,8 +37,8 @@ exported_functions = ["_malloc",
|
||||
"_Zlib_Create",
|
||||
"_Zlib_Load",
|
||||
"_Zlib_Destroy",
|
||||
"_Zlib_GetPaths",
|
||||
"_Zlib_GetFileByPath"]
|
||||
"_Zlib_GetPathsInArchive",
|
||||
"_Zlib_GetFileFromArchive"]
|
||||
|
||||
libZlib_src_path = "../src/zlib-1.2.11"
|
||||
input_zlib_sources = ["inflate.c", "zutil.c", "adler32.c", "crc32.c", "inftrees.c",
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "../../../../DesktopEditor/common/Types.h"
|
||||
#include "../../../../DesktopEditor/common/File.h"
|
||||
#include "../../wasm/src/base.h"
|
||||
#include "../../../OfficeUtils.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -10,8 +11,19 @@ unsigned int GetLength(BYTE* x)
|
||||
return x[0] | x[1] << 8 | x[2] << 16 | x[3] << 24;
|
||||
}
|
||||
|
||||
bool RFC(std::wstring& file_name, BYTE*& pData, long& nSize, void* pParam)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
COfficeUtils cOU;
|
||||
cOU.CompressFileOrDirectory(NSFile::GetProcessDirectory() + L"/test", NSFile::GetProcessDirectory() + L"/test.zip");
|
||||
RequestFileCallback callback = RFC;
|
||||
bool bResult;
|
||||
cOU.CompressFilesFromMemory(NSFile::GetProcessDirectory() + L"/test.zip", callback, NULL, -1, &bResult);
|
||||
|
||||
DWORD nBytesCount;
|
||||
BYTE* pData;
|
||||
NSFile::CFileBinary oFile;
|
||||
|
||||
@ -39,12 +39,9 @@ window.onload = function()
|
||||
window.loadedZip = window.nativeZlibEngine.openZip(e.target.result);
|
||||
if (!window.loadedZip)
|
||||
return;
|
||||
var paths = window.loadedZip.GetPaths();
|
||||
for (var i = 0; i < paths.length; i++)
|
||||
{
|
||||
var file = window.loadedZip.GetFileByPath(paths[i]);
|
||||
window.writeFile(file);
|
||||
}
|
||||
var files = window.loadedZip.GetFilesInArchive();
|
||||
for (var i = 0; i < files.length; i++)
|
||||
window.writeFile(files[i]);
|
||||
window.loadedZip.closeZip();
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
@ -59,5 +56,5 @@ window.writeFile = function(file)
|
||||
var dst = document.getElementById("main");
|
||||
dst.innerHTML += file.path + ' ' + file.length + ' ';
|
||||
if (file.length < 100)
|
||||
dst.innerHTML += file.file;
|
||||
dst.innerHTML += "in"; // Uint8Array file.file;
|
||||
};
|
||||
|
||||
@ -143,13 +143,34 @@ function Zlib()
|
||||
this.isInit = false;
|
||||
this.paths = [];
|
||||
this.files = [];
|
||||
|
||||
this.CreateArchiveFromFiles(_files)
|
||||
{
|
||||
var tmpBuffer;
|
||||
// вычисление размера
|
||||
tmpBuffer[i + 0] = (val & (255 << 0)) >> 0;
|
||||
tmpBuffer[i + 1] = (val & (255 << 8)) >> 8;
|
||||
tmpBuffer[i + 2] = (val & (255 << 16)) >> 16;
|
||||
tmpBuffer[i + 3] = (val & (255 << 24)) >> 24;
|
||||
}
|
||||
|
||||
this.GetPaths = function()
|
||||
this.GetPathsInArchive = function()
|
||||
{
|
||||
return (this.isInit ? this.paths : []);
|
||||
return (this.isInit && this.zipFile != 0 ? this.paths : []);
|
||||
}
|
||||
|
||||
this.GetFileByPath = function(_path)
|
||||
this.GetFilesInArchive = function()
|
||||
{
|
||||
if (!this.isInit) return [];
|
||||
if (this.zipFile == 0) return [];
|
||||
|
||||
var _paths = this.GetPathsInArchive();
|
||||
for (var i = 0; i < _paths.length; i++)
|
||||
this.GetFileInArchive(_paths[i]);
|
||||
return this.files;
|
||||
}
|
||||
|
||||
this.GetFileInArchive = function(_path)
|
||||
{
|
||||
if (!this.isInit) return null;
|
||||
if (this.zipFile == 0) return null;
|
||||
@ -161,7 +182,7 @@ function Zlib()
|
||||
var pointer = Module["_Zlib_Malloc"](tmp.len);
|
||||
Module["HEAP8"].set(tmp.buf, pointer);
|
||||
|
||||
var pointerFile = Module["_Zlib_GetFileByPath"](this.zipFile, pointer);
|
||||
var pointerFile = Module["_Zlib_GetFileFromArchive"](this.zipFile, pointer);
|
||||
if (pointerFile == 0)
|
||||
{
|
||||
Module["_Zlib_Free"](pointer);
|
||||
@ -172,10 +193,10 @@ function Zlib()
|
||||
var len = _lenFile[0];
|
||||
|
||||
var buffer = new Uint8Array(Module["HEAP8"].buffer, pointerFile + 4, len);
|
||||
var file = {
|
||||
path : _path,
|
||||
length : len,
|
||||
file : readFromUtf8(buffer, 0, len)
|
||||
var file = {
|
||||
path : _path,
|
||||
length : len,
|
||||
file : buffer
|
||||
};
|
||||
this.files.push(file);
|
||||
|
||||
@ -197,14 +218,14 @@ function Zlib()
|
||||
|
||||
// грузим данные
|
||||
this.zipFile = Module["_Zlib_Load"](FileRawData, FileRawDataSize);
|
||||
if (0 == this.zipFile)
|
||||
if (this.zipFile == 0)
|
||||
{
|
||||
Module["_Zlib_Free"](FileRawData);
|
||||
return null;
|
||||
}
|
||||
|
||||
// получаем пути в архиве
|
||||
var pointer = Module["_Zlib_GetPaths"](this.zipFile);
|
||||
var pointer = Module["_Zlib_GetPathsInArchive"](this.zipFile);
|
||||
if (pointer == 0)
|
||||
{
|
||||
Module["_Zlib_Destroy"](this.zipFile);
|
||||
@ -230,7 +251,7 @@ function Zlib()
|
||||
this.closeZip = function()
|
||||
{
|
||||
if (!this.isInit) return;
|
||||
Module["_Zlib_Destroy"](this.zipFile);
|
||||
if (this.zipFile != 0) Module["_Zlib_Destroy"](this.zipFile);
|
||||
this.paths = [];
|
||||
this.files = [];
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ void Zlib_Destroy(Zlib* p)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char* Zlib_GetPaths(Zlib* p)
|
||||
unsigned char* Zlib_GetPathsInArchive(Zlib* p)
|
||||
{
|
||||
if (p && p->isInit())
|
||||
{
|
||||
@ -126,7 +126,7 @@ unsigned char* Zlib_GetPaths(Zlib* p)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
unsigned char* Zlib_GetFileByPath(Zlib* p, const char* path)
|
||||
unsigned char* Zlib_GetFileFromArchive(Zlib* p, const char* path)
|
||||
{
|
||||
if (p && p->isInit())
|
||||
{
|
||||
|
||||
@ -28,8 +28,9 @@ ZLIB_DECL_EXPORT Zlib* Zlib_Create();
|
||||
ZLIB_DECL_EXPORT Zlib* Zlib_Load(unsigned char* buffer, unsigned long size);
|
||||
ZLIB_DECL_EXPORT void Zlib_Destroy(Zlib* p);
|
||||
|
||||
ZLIB_DECL_EXPORT unsigned char* Zlib_GetPaths(Zlib* p);
|
||||
ZLIB_DECL_EXPORT unsigned char* Zlib_GetFileByPath(Zlib* p, const char* path);
|
||||
ZLIB_DECL_EXPORT unsigned char* Zlib_GetPathsInArchive(Zlib* p);
|
||||
ZLIB_DECL_EXPORT unsigned char* Zlib_GetFileFromArchive(Zlib* p, const char* path);
|
||||
ZLIB_DECL_EXPORT unsigned char* Zlib_CompressFiles(Zlib* p, unsigned char* tree);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user