Download wp-calypso/desktop/app/lib/archiver/index.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/desktop/app/lib/archiver/index.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/desktop/app/lib/archiver/index.js
-
curl -L -o index.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/desktop/app/lib/archiver/index.js
1.49 kB
| const fs = require( 'fs' ); | |
| const path = require( 'path' ); | |
| const archiver = require( 'archiver' ); | |
| const log = require( '../../lib/logger' )( 'desktop:lib:archiver' ); | |
| module.exports = { | |
| /** | |
| * Compresses `contents` to the archive at `dst`. | |
| * @param {string[]} contents Paths to be zipped | |
| * @param {string} dst Path to destination archive | |
| * @param {function():void} onZipped Callback invoked when archive is complete | |
| */ | |
| zipContents: ( contents, dst, onZipped ) => { | |
| const output = fs.createWriteStream( dst ); | |
| const archive = archiver( 'zip', { | |
| zlib: { level: 9 }, | |
| } ); | |
| output.on( 'close', function () { | |
| log.debug( 'Archive finalized: %s bytes written', archive.pointer() ); | |
| if ( typeof onZipped === 'function' ) { | |
| onZipped(); | |
| } | |
| } ); | |
| // Catch warnings (e.g. stat failures and other non-blocking errors) | |
| archive.on( 'warning', function ( err ) { | |
| log.warn( 'Unexpected error: ', err ); | |
| } ); | |
| archive.on( 'error', function ( err ) { | |
| throw err; | |
| } ); | |
| archive.pipe( output ); | |
| for ( let i = 0; i < contents.length; i++ ) { | |
| const src = contents[ i ]; | |
| const zipSubdir = path.basename( dst ).replace( '.zip', '' ); | |
| const dstInZipSubdir = path.join( zipSubdir, path.basename( src ) ); | |
| const stat = fs.lstatSync( src ); | |
| if ( stat.isDirectory() ) { | |
| archive.directory( path.join( src, path.sep ), dstInZipSubdir ); | |
| continue; | |
| } | |
| archive.file( src, { name: dstInZipSubdir } ); | |
| } | |
| archive.finalize(); | |
| }, | |
| }; | |