node-archiver icon indicating copy to clipboard operation
node-archiver copied to clipboard

directory() method is not working.

Open trymeouteh opened this issue 5 months ago • 0 comments

Archiver Version 7.0.1 Node Version 20.17.0 OS: Linux Mint

When I use the directory() to copy a directory and its content into the archive file, nothing happens and the directory is not copied and pasted into the archive file. The text file is copied and pasted into the archive and the newly created file is present in the final archived file.

import http from 'http';
import archiver from 'archiver';

const port = 8080;

http
	.createServer(function (request, response) {
		//HTTP headers to tell browser URL is a ZIP file
		response.setHeader('Content-Type', 'application/zip');

		//Zip file name
		response.setHeader('Content-disposition', 'attachment; filename=My Zip File.zip');

		const zip = archiver('zip');

		//Send the file to the page output.
		zip.pipe(response);

		//Create a file named "A Text File 1.txt" in the ZIP file in a folder named My Folder
		zip.append('My generated text for my generated text file', { name: 'My Folder/A Text File 1.txt' });

		//Add a file named "my-text-file.txt" from localhost and add it to the ZIP file in a folder named My Folder and rename it to "A Text File 2.txt"

		zip.file('my-text-file.txt', { name: '/My Folder/A Text File 2.txt' });

		zip.directory('node_modules/', 'new-subdir');

		//Finish the zip stream
		zip.finalize();
	})
	.listen(port);

trymeouteh avatar Sep 17 '24 03:09 trymeouteh