-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
antelle
committed
Feb 5, 2021
1 parent
eed57a1
commit 51e0ed9
Showing
11 changed files
with
384 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable no-console,no-unused-vars */ | ||
const StreamZip = require('./'); | ||
|
||
(async () => { | ||
console.log('Loading zip...'); | ||
|
||
const zip = new StreamZip.async({ file: './test/ok/normal.zip' }); | ||
const entriesCount = await zip.entriesCount; | ||
|
||
console.log(`Done in ${process.uptime()}s. Entries read: ${entriesCount}`); | ||
|
||
const entry = await zip.entry('README.md'); | ||
console.log('Entry for README.md:', entry); | ||
|
||
const data = await zip.entryData('README.md'); | ||
const firstLine = data.toString().split('\n')[0].trim(); | ||
console.log(`First line of README.md: "${firstLine}"`); | ||
|
||
async function streamDataToStdOut() { | ||
const stm = await zip.stream('README.md'); | ||
console.log('README.md contents streamed:\n'); | ||
stm.pipe(process.stdout); | ||
} | ||
|
||
async function extractEntry() { | ||
await zip.extract('README.md', './tmp'); | ||
} | ||
|
||
async function extractAll() { | ||
const extracted = await zip.extract(null, './tmp'); | ||
console.log(`Extracted ${extracted} entries`); | ||
} | ||
|
||
await zip.close(); | ||
})().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable no-console,no-unused-vars */ | ||
const StreamZip = require('./'); | ||
|
||
const zip = new StreamZip({ file: './test/ok/normal.zip' }); | ||
zip.on('error', (err) => { | ||
console.error('ERROR: ' + err); | ||
}); | ||
zip.on('ready', () => { | ||
const entriesCount = zip.entriesCount; | ||
console.log(`Done in ${process.uptime()}s. Entries read: ${entriesCount}`); | ||
|
||
const entry = zip.entry('README.md'); | ||
console.log('Entry for README.md:', entry); | ||
|
||
const data = zip.entryDataSync('README.md'); | ||
const firstLine = data.toString().split('\n')[0].trim(); | ||
console.log(`First line of README.md: "${firstLine}"`); | ||
|
||
zip.close(); | ||
|
||
function streamDataToStdOut() { | ||
zip.stream('README.md', (err, stm) => { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
console.log('README.md contents streamed:\n'); | ||
stm.pipe(process.stdout); | ||
}); | ||
} | ||
|
||
function extractEntry() { | ||
zip.extract('README.md', './tmp', (err) => { | ||
console.log(err ? err : 'Entry extracted'); | ||
zip.close(); | ||
}); | ||
} | ||
|
||
function extractAll() { | ||
zip.extract(null, './tmp', (err, count) => { | ||
console.log(err ? err : `Extracted ${count} entries`); | ||
zip.close(); | ||
}); | ||
} | ||
}); | ||
zip.on('extract', (entry, file) => { | ||
console.log('extract', entry.name, file); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.