Skip to content

directory() method is not working. #783

@trymeouteh

Description

@trymeouteh

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions