Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
readLocalFileHeader()
andClass: LocalFileHeader
.openReadStreamLowLevel()
.getFileNameLowLevel()
andparseExtraFields()
. Added fields toClass: Entry
:fileNameRaw
,extraFieldRaw
,fileCommentRaw
.examples/compareCentralAndLocalHeaders.js
that demonstrate many of these low level APIs."engines"
field ofpackage.json
.openReadStream()
with an explicitlynull
options parameter (as opposed to omitted).Here's some of the readme additions copied into this PR for convenience:
getFileNameLowLevel(generalPurposeBitFlag, fileNameBuffer, extraFields, strictFileNames)
If you are setting
decodeStrings
tofalse
, then this function can be used to decode the file name yourself.This function is effectively used internally by yauzl to populate the
entry.fileName
field whendecodeStrings
istrue
.WARNING: This method of getting the file name bypasses the security checks in
validateFileName()
.You should call that function yourself to be sure to guard against malicious file paths.
generalPurposeBitFlag
can be found on anEntry
orLocalFileHeader
.Only General Purpose Bit 11 is used, and only when an Info-ZIP Unicode Path Extra Field cannot be found in
extraFields
.fileNameBuffer
is aBuffer
representing the file name field of the entry.This is
entry.fileNameRaw
orlocalFileHeader.fileName
.extraFields
is the parsed extra fields array fromentry.extraFields
orparseExtraFields()
.strictFileNames
is a boolean, the same as the option of the same name inopen()
.When
false
, backslash characters (\
) will be replaced with forward slash characters (/
).This function always returns a string, although it may not be a valid file name.
See
validateFileName()
.parseExtraFields(extraFieldBuffer)
This function is used internally by yauzl to compute
entry.extraFields
.It is exported in case you want to call it on
localFileHeader.extraField
.extraFieldBuffer
is aBuffer
, such aslocalFileHeader.extraField
.Returns an
Array
with each item in the form{id: id, data: data}
,where
id
is aNumber
anddata
is aBuffer
.Throws an
Error
if the data encodes an item with a size that exceeds the bounds of the buffer.You may want to surround calls to this function with
try { ... } catch (err) { ... }
to handle the error.readLocalFileHeader(entry, [options], callback)
This is a low-level function you probably don't need to call.
The intended use case is either preparing to call
openReadStreamLowLevel()
or simply examining the content of the local file header out of curiosity or for debugging zip file structure issues.
entry
is an entry obtained fromEvent: "entry"
.An
entry
in this library is a file's metadata from a Central Directory Header,and this function gives the corresponding redundant data in a Local File Header.
options
may be omitted ornull
, and has the following defaults:If
minimal
isfalse
(or omitted ornull
), the callback receives a fullLocalFileHeader
.If
minimal
istrue
, the callback receives an object with a single property and no prototype{fileDataStart: fileDataStart}
.For typical zipfile reading usecases, this field is the only one you need,
and yauzl internally effectively uses the
{minimal: true}
option as part ofopenReadStream()
.The
callback
receives(err, localFileHeaderOrAnObjectWithJustOneFieldDependingOnTheMinimalOption)
,where the type of the second parameter is described in the above discussion of the
minimal
option.openReadStreamLowLevel(fileDataStart, compressedSize, relativeStart, relativeEnd, decompress, uncompressedSize, callback)
This is a low-level function available for advanced use cases. You probably want
openReadStream()
instead.The intended use case for this function is calling
readEntry()
andreadLocalFileHeader()
with{minimal: true}
first,and then opening the read stream at a later time, possibly after closing and reopening the entire zipfile,
possibly even in a different process.
The parameters are all integers and booleans, which are friendly to serialization.
fileDataStart
- fromlocalFileHeader.fileDataStart
compressedSize
- fromentry.compressedSize
relativeStart
- the resolved value ofoptions.start
fromopenReadStream()
. Must be a non-negative integer, notnull
. Typically0
to start at the beginning of the data.relativeEnd
- the resolved value ofoptions.end
fromopenReadStream()
. Must be a non-negative integer, notnull
. Typicallyentry.compressedSize
to include all the data.decompress
- boolean indicating whether the data should be piped through a zlib inflate stream.uncompressedSize
- fromentry.uncompressedSize
. Only used whenvalidateEntrySizes
istrue
. IfvalidateEntrySizes
isfalse
, this value is ignored, but must still be present, not omitted, in the arguments; you have to give it some value, even if it'snull
.callback
- receives(err, readStream)
, the same as foropenReadStream()
This low-level function does not read any metadata from the underlying storage before opening the read stream.
This is both a performance feature and a safety hazard.
None of the integer parameters are bounds checked.
None of the validation from
openReadStream()
with respect to compression and encryption is done here either.Only the bounds checks from
validateEntrySizes
are done, because that is part of processing the stream data.Class: LocalFileHeader
This is a trivial class that has no methods and only the following properties.
The constructor is available to call, but it doesn't do anything.
See
readLocalFileHeader()
.See the zipfile spec for what these fields mean.
fileDataStart
-Number
: inferred fromfileNameLength
,extraFieldLength
, and this struct's position in the zipfile.versionNeededToExtract
-Number
generalPurposeBitFlag
-Number
compressionMethod
-Number
lastModFileTime
-Number
lastModFileDate
-Number
crc32
-Number
compressedSize
-Number
uncompressedSize
-Number
fileNameLength
-Number
extraFieldLength
-Number
fileName
-Buffer
extraField
-Buffer
Note that unlike
Class: Entry
, thefileName
andextraField
are completely unprocessed.This notably lacks Unicode and ZIP64 handling as well as any kind of safety validation on the file name.
See also
parseExtraFields()
.Also note that if your object is missing some of these fields,
make sure to read the docs on the
minimal
option inreadLocalFileHeader()
.