How to use the unused-filename function in unused-filename

To help you get started, we’ve selected a few unused-filename examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adishegde / media_hub / src / app / utils / fileDownloader.js View on Github external
// Store a reference to res
            this._response = res;

            let fileName = this._response.headers["content-disposition"];
            // Extract filename from header. Assumption is that the
            // header is exactly as returned by the http service.
            // Might throw errors for other headers
            fileName = fileName.replace(`inline; filename="`, "");
            // Remove trailing double quote
            fileName = fileName.slice(0, fileName.length - 1);

            // Get full file path
            let filePath = Path.join(this.directory, fileName);

            // Get unused filename
            UnusedFileName(filePath)
                .then(unusedpath => {
                    // Assign the file name to instance
                    this._filepath = unusedpath;
                })
                .then(() => {
                    // No point wrapping this in promise. Communication with
                    // outside world occurs through events

                    // Extract file size from header
                    this._size = parseInt(
                        this._response.headers["content-length"],
                        10
                    );
                    // Keep track of bytes downloaded
                    this._bytesDownloaded = 0;

unused-filename

Get an unused filename by appending a number if it exists: `file.txt` → `file (1).txt`

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis

Popular unused-filename functions