# yauzl
[![Build Status](https://travis-ci.org/thejoshwolfe/yauzl.svg?branch=master)](https://travis-ci.org/thejoshwolfe/yauzl)
[![Coverage Status](https://img.shields.io/coveralls/thejoshwolfe/yauzl.svg)](https://coveralls.io/r/thejoshwolfe/yauzl)
yet another unzip library for node. For zipping, see
[yazl](https://github.com/thejoshwolfe/yazl).
Design principles:
* Follow the spec.
Don't scan for local file headers.
Read the central directory for file metadata.
(see [No Streaming Unzip API](#no-streaming-unzip-api)).
* Don't block the JavaScript thread.
Use and provide async APIs.
* Keep memory usage under control.
Don't attempt to buffer entire files in RAM at once.
* Never crash (if used properly).
Don't let malformed zip files bring down client applications who are trying to catch errors.
* Catch unsafe file names.
See `validateFileName()`.
## Usage
```js
var yauzl = require("yauzl");
var fs = require("fs");
var path = require("path");
var mkdirp = require("mkdirp"); // or similar
yauzl.open("path/to/file.zip", {lazyEntries: true}, function(err, zipfile) {
if (err) throw err;
zipfile.readEntry();
zipfile.on("entry", function(entry) {
if (/\/$/.test(entry.fileName)) {
// directory file names end with '/'
mkdirp(entry.fileName, function(err) {
if (err) throw err;
zipfile.readEntry();
});
} else {
// file entry
zipfile.openReadStream(entry, function(err, readStream) {
if (err) throw err;
// ensure parent directory exists
mkdirp(path.dirname(entry.fileName), function(err) {
if (err) throw err;
readStream.pipe(fs.createWriteStream(entry.fileName));
readStream.on("end", function() {
zipfile.readEntry();
});
});
});
}
});
});
```
## API
The default for every optional `callback` parameter is:
```js
function defaultCallback(err) {
if (err) throw err;
}
```
### open(path, [options], [callback])
Calls `fs.open(path, "r")` and reads the `fd` effectively the same as `fromFd()` would.
`options` may be omitted or `null`. The defaults are `{autoClose: true, lazyEntries: false, decodeStrings: true}`.
`autoClose` is effectively equivalent to:
```js
zipfile.once("end", function() {
zipfile.close();
});
```
`lazyEntries` indicates that entries should be read only when `readEntry()` is called.
If `lazyEntries` is `false`, `entry` events will be emitted as fast as possible to allow `pipe()`ing
file data from all entries in parallel.
This is not recommended, as it can lead to out of control memory usage for zip files with many entries.
See [issue #22](https://github.com/thejoshwolfe/yauzl/issues/22).
If `lazyEntries` is `true`, an `entry` or `end` event will be emitted in response to each call to `readEntry()`.
This allows processing of one entry at a time, and will keep memory usage under control for zip files with many entries.
`decodeStrings` is the default and causes yauzl to decode strings with `CP437` or `UTF-8` as required by the spec.
The exact effects of turning this option off are:
* `zipfile.comment`, `entry.fileName`, and `entry.fileComment` will be `Buffer` objects instead of `String`s.
* Any Info-ZIP Unicode Path Extra Field will be ignored. See `extraFields`.
* Automatic file name validation will not be performed. See `validateFileName()`.
The `callback` is given the arguments `(err, zipfile)`.
An `err` is provided if the End of Central Directory Record cannot be found, or if its metadata appears malformed.
This kind of error usually indicates that this is not a zip file.
Otherwise, `zipfile` is an instance of `ZipFile`.
### fromFd(fd, [options], [callback])
Reads from the fd, which is presumed to be an open .zip file.
Note that random access is required by the zip file specification,
so the fd cannot be an open socket or any other fd that does not support random access.
`options` may be omitted or `null`. The defaults are `{autoClose: false, lazyEntries: false, decodeStrings: true}`.
See `open()` for the meaning of the options and callback.
### fromBuffer(buffer, [options], [callback])
Like `fromFd()`, but reads from a RAM buffer instead of an open file.
`buffer` is a `Buffer`.
If a `ZipFile` is acquired from this method,
it will never emit the `close` event,
and calling `close()` is not necessary.
`options` may be omitted or `null`. The defaults are `{lazyEntries: false, decodeStrings: true}`.
See `open()` for the meaning of the options and callback.
The `autoClose` option is ignored for this method.
### fromRandomAccessReader(reader, totalSize, [options], [callback])
This method of reading a zip file allows clients to implement their own back-end file system.
For example, a client might translate read calls into network requests.
The `reader` parameter must be of a type that is a subclass of
[RandomAccessReader](#class-randomaccessreader) that implements the required methods.
The `totalSize` is a Number and indicates the total file size of the zip file.
`options` may be omitted or `null`. The defaults are `{autoClose: true, lazyEntries: false, decodeStrings: true}`.
See `open()` for the meaning of the options and callback.
### dosDateTimeToDate(date, time)
Converts MS-DOS `date` and `time` data into a JavaScript `Date` object.
Each parameter is a `Number` treated as an unsigned 16-bit integer.
Note that this format does not support timezones,
so the returned object will use the local timezone.
### validateFileName(fileName)
Returns `null` or a `String` error message depending on the validity of `fileName`.
If `fileName` starts with `"/"` or `/[A-Za-z]:\//` or if it contains `".."` path segments or `"\\"`,
this function returns an error message appropriate for use like this:
```js
var errorMessage = yauzl.validateFileName(fileName);
if (errorMessage != null) throw new Error(errorMessage);
```
This function is automatically run for each entry, as long as `decodeStrings` is `true`.
See `open()` and `Event: "entry"` for more information.
### Class: ZipFile
The constructor for the class is not part of the public API.
Use `open()`, `fromFd()`, `fromBuffer()`, or `fromRandomAccessReader()` instead.
#### Event: "entry"
Callback gets `(entry)`, which is an `Entry`.
See `open()` and `readEntry()` for when this event is emitted.
If `decodeStrings` is `true`, entries emitted via this event have already passed file name validation.
See `validateFileName()` and `open()` for more information.
#### Event: "end"
Emitted after the last `entry` event has been emitted.
See `open()` and `readEntry()` for more info on when this event is emitted.
#### Event: "close"
Emitted after the fd is actually closed.
This is after calling `close()` (or after the `end` event when `autoClose` is `true`),
and after all stream pipelines created from `openReadStream()` have finished reading data from the fd.
If this `ZipFile` was acquired from `fromRandomAccessReader()`,
the "fd" in the previous paragraph refers to the `RandomAccessReader` implemented by the client.
If this `ZipFile` was acquired from `fromBuffer()`, this event is never emitted.
#### Event: "error"
Emitted in the case of errors with reading the zip file.
(Note that other errors can be emitted from the streams created from `openReadStream()` as well.)
After this event has been emitted, no further `entry`, `end`, or `error` events will be emitted,
but the `close` event may still be emitted.
#### readEntry()
Causes this `ZipFile` to emit an `entry` or `end` event (or an `error` event).
This method must only be called when this `ZipFile` was created with the `lazyEntries` option set to `true` (see `open()`).
When this `ZipFile` was created with the `lazyEntries` option set to `true`,
`entry` and `end` events are only ever emitted in response to this method call.
The event that is emitted in response to this method will not be emitted until after this method has returned,
so it is safe to c
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
VSCODE csharp extension (995个子文件)
range.bnf 629B
install.complete 0B
OmniSharp.exe.config 7KB
MSBuild.exe.config 7KB
Microsoft.CodeAnalysis.CSharp.ni.dll 18.29MB
Microsoft.CodeAnalysis.ni.dll 17.1MB
System.Private.CoreLib.ni.dll 10.64MB
coreclr.dll 5.17MB
Microsoft.VisualStudio.Debugger.Engine.ni.dll 4.71MB
Microsoft.CodeAnalysis.CSharp.dll 4.24MB
System.Reflection.Metadata.ni.dll 3.73MB
Microsoft.DiaSymReader.McgInterop.ni.dll 3.41MB
mscorlib.dll 2.55MB
System.ServiceModel.dll 2.41MB
Microsoft.CodeAnalysis.Workspaces.dll 1.96MB
Microsoft.VisualStudio.VIL.Host.ni.dll 1.92MB
Microsoft.CodeAnalysis.dll 1.91MB
vsdebugeng.impl.dll 1.9MB
Microsoft.CodeAnalysis.Features.dll 1.86MB
mscordaccore.dll 1.69MB
Microsoft.VisualStudio.VIL.ni.dll 1.62MB
System.Xml.ReaderWriter.ni.dll 1.53MB
System.Collections.Immutable.ni.dll 1.53MB
System.dll 1.39MB
mscordbi.dll 1.38MB
Microsoft.Build.dll 1.33MB
System.Linq.Expressions.ni.dll 1.25MB
Newtonsoft.Json.ni.dll 1.22MB
Microsoft.DiaSymReader.Native.amd64.dll 1.21MB
Microsoft.Build.Tasks.Core.dll 1.13MB
Microsoft.CSharp.ni.dll 1.09MB
vsdebugeng.manimpl.ni.dll 1.08MB
Microsoft.VisualStudio.Debugger.Metadata.ni.dll 1.04MB
clrjit.dll 1.02MB
VSDebugEng.dll 1014KB
ucrtbase.dll 939KB
System.Xml.XmlSerializer.ni.dll 903KB
System.Xml.dll 901KB
System.Linq.ni.dll 893KB
Microsoft.CodeAnalysis.ExpressionEvaluator.ExpressionCompiler.ni.dll 857KB
Microsoft.CodeAnalysis.CSharp.Features.dll 785KB
System.Text.Encoding.CodePages.dll 749KB
System.Text.Encoding.CodePages.dll 749KB
Microsoft.MIDebugEngine.ni.dll 748KB
System.Private.Interop.ni.dll 709KB
sos.dll 701KB
msvcp140.dll 634KB
Microsoft.CodeAnalysis.CSharp.Workspaces.dll 629KB
System.Collections.ni.dll 615KB
Microsoft.DiaSymReader.PortablePdb.ni.dll 615KB
System.Xml.ReaderWriter.dll 592KB
VSDebugUI.dll 586KB
hostpolicy.dll 532KB
System.IdentityModel.dll 525KB
Newtonsoft.Json.dll 523KB
Newtonsoft.Json.dll 523KB
Newtonsoft.Json.dll 514KB
Newtonsoft.Json.dll 498KB
Newtonsoft.Json.dll 458KB
Newtonsoft.Json.dll 458KB
System.Reflection.Metadata.dll 454KB
Microsoft.CodeAnalysis.ExpressionEvaluator.ResultProvider.ni.dll 451KB
System.Collections.Concurrent.ni.dll 424KB
Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator.ExpressionCompiler.ni.dll 422KB
Esent.Interop.dll 403KB
System.Text.RegularExpressions.ni.dll 392KB
System.IO.FileSystem.ni.dll 378KB
NuGet.Protocol.Core.v3.dll 366KB
NuGet.Protocol.Core.v3.dll 366KB
mscorrc.debug.dll 362KB
NuGet.Protocol.Core.v3.dll 343KB
NuGet.Protocol.Core.v3.dll 343KB
NuGet.Protocol.Core.v3.dll 338KB
Microsoft.Build.Utilities.Core.dll 322KB
NuGet.Commands.dll 313KB
NuGet.Commands.dll 313KB
NuGet.Commands.dll 312KB
System.Net.Primitives.dll 300KB
hostfxr.dll 290KB
System.Security.Cryptography.Algorithms.ni.dll 289KB
Microsoft.AspNetCore.Server.Kestrel.dll 277KB
libuv.dll 275KB
System.Net.Http.dll 265KB
System.Dynamic.Runtime.ni.dll 265KB
Microsoft.AspNetCore.Diagnostics.dll 258KB
System.Collections.Immutable.dll 239KB
Microsoft.CodeAnalysis.Workspaces.Desktop.dll 237KB
System.Core.dll 235KB
clretwrc.dll 233KB
System.Net.Sockets.dll 211KB
Microsoft.DotNet.ProjectModel.dll 210KB
Microsoft.NET.Sdk.Publish.Tasks.dll 210KB
System.Runtime.Extensions.ni.dll 201KB
Microsoft.DiaSymReader.ni.dll 195KB
libclrdbg.dll 189KB
System.Threading.Tasks.Parallel.ni.dll 186KB
System.Diagnostics.Process.ni.dll 186KB
OpenDebugAD7.dll 186KB
Microsoft.MICore.dll 185KB
NuGet.Packaging.dll 179KB
共 995 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
a13197987125
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于springboot+layui的医院日常耗材管理系统.zip
- 计算机毕业设计-ASP.NET教育报表管理系统-权限管理模块(源代码+)-毕设源码实例.zip
- 计算机毕业设计-ASP.NET教务信息管理系统的设计与实现(源代码+)-毕设源码实例.zip
- Eleven的精益供应链管理-碓胤咨询龚胤全.rar
- 5套光伏、储能、充电收益测算表.zip
- C2 供应链集成演示平台操作手册(详细版).rar
- 3套光储充一体化站CAD+PDF图纸.zip
- Screenshot_20240426_195831_com.huawei.android.launcher.jpg
- 2000-2023年各省专利侵权结案数据.xlsx
- C#使用NPOI操作合并单元格
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功