In this step, you’ll use adm-zip to compress and archive the directory you created in the previous section. In the next step, you’ll archive a directory using the adm-zip module. You’ve now created the project directory, installed adm-zip, and created a directory with files for archiving. will move you to the parent directory, which is zip_app. Move back into the main project directory with the following command: yes "dummy content" | head -n 600000 > file3.txtįinally, download an image into the directory using curl:.yes "dummy content" | head -n 300000 > file2.txtĬreate another file with the dummy content string repeated 600,000 lines:.Finally, you redirect the head output to a new file file1.txt using >.Ĭreate a second file with the string “dummy content” repeated 300,000 lines: The -n option specifies the number of lines that should be written to the standard output. The head command prints part of the given input into the standard output. Using the pipe command |, you send the output from the yes command to be used as input for the head command. The yes command logs the string dummy content repeatedly. yes "dummy content" | head -n 100000 > file1.txt.This will help to demonstrate ZIP compression when you archive this directory.Ĭreate the file1.txt and fill it with dummy content using the following command: The three files will be filled with dummy content to make their file sizes larger. In this directory, you will create three text files and download an image. Next, create a directory called test and move into it: Next, install adm-zip with the npm install command:Īfter you run the command, npm will install adm-zip and update the package.json file. The -y option creates a default package.json file. Inside the directory, create a package.json file to manage the project dependencies: Navigate into the newly created directory with the cd command: You’ll archive this directory in the next section.Ĭreate a directory called zip_app with the following command: You’ll also create another directory containing text files and an image. This directory is where you’ll keep your program files. In this step, you’ll create the directory for your project and install adm-zip as a dependency. See the tutorial How To Work with Files using the fs Module in Node.js to review working with files. Knowledge of how to work with files in Node.js. Visit our tutorial Understanding the Event Loop, Callbacks, Promises, and Async/Await in JavaScript to learn the basics. Knowledge of how to write a Node.js program, see How To Write and Run Your First Program in Node.js.Ī basic understanding of asynchronous programming in JavaScript. Follow How to Install Node.js and Create a Local Development Environment to install Node.js. Node.js installed on your local or server environment. After that, you’ll add a file to an existing ZIP archive, and then finally, you’ll extract a ZIP archive into a directory. You’ll then list the ZIP archive contents. First, you’ll combine multiple files into a ZIP archive using adm-zip. In this tutorial, you will use adm-zip module to compress, read, and decompress files. In Node.js, you can use the adm-zip module to create and read ZIP archives. The algorithm can reconstruct the data without any data loss. A ZIP file is an archive format that packs and compresses files with the lossless compression algorithm. To get around this, you can group the files into a single ZIP file. Some of these platforms have file size limits, and won’t accept large files. Sooner or later you may need to transfer the files to other servers or upload multiple files from your local machine to different platforms. As your files grow in size, they start taking significant space on your hard drive. Working with files is one of the common tasks among developers. The author selected Open Sourcing Mental Illness to receive a donation as part of the Write for DOnations program.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |