Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "zipster", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "TypeScript library built for Node backends to create ZIP files with password protection", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,6 +9,15 @@ # Zipster | ||
**This project is still in development and is not available on NPM as yet.** | ||
**This project is still in development. Please report any bugs or feature requests as an | ||
[issue](https://github.com/ToeFungi/zipper/issues/new).** | ||
## Example | ||
## Installation | ||
Use the following command to install the package: | ||
``` | ||
npm i zipster | ||
``` | ||
## Usage | ||
The following example will create a password-protected ZIP file called `protected.zip` in the execution directory, | ||
@@ -30,3 +39,3 @@ containing the `test.csv` with the password to access the ZIP being `foo-fighters`. | ||
zipster.create(fileToZip, options) | ||
.then((directory: string) => console.log({ directory }, 'Successfully created ZIP')) | ||
.then((outputDirectory: string) => console.log({ outputDirectory }, 'Successfully created ZIP')) | ||
``` |
@@ -1,2 +0,2 @@ | ||
import * as path from 'path' | ||
import * as nodePath from 'path' | ||
@@ -6,19 +6,19 @@ import { ZipsterError } from '../errors/ZipsterError' | ||
/** | ||
* File Parts encapsulates the important components of a file and it's directory | ||
* File Parts encapsulates the important components of a file and it's path | ||
*/ | ||
class FileParts { | ||
private readonly path: string | ||
private readonly fileName: string | ||
private readonly directory: string | ||
private readonly fileExtension: string | ||
constructor(directory: string) { | ||
const [fileName, fileExtension] = path.basename(directory) | ||
constructor(path: string) { | ||
const [fileName, fileExtension] = nodePath.basename(path) | ||
.split('.') | ||
if (!fileName || !fileExtension) { | ||
throw new ZipsterError('Directory missing file name or file extension') | ||
throw new ZipsterError('Path missing file name or file extension') | ||
} | ||
this.path = path | ||
this.fileName = fileName | ||
this.directory = directory | ||
this.fileExtension = fileExtension | ||
@@ -42,6 +42,6 @@ } | ||
/** | ||
* Get the directory of the file | ||
* Get the path of the file | ||
*/ | ||
public getDirectory(): string { | ||
return this.directory | ||
public getPath(): string { | ||
return this.path | ||
} | ||
@@ -48,0 +48,0 @@ } |
@@ -13,3 +13,3 @@ import { ArchiverOptions } from 'archiver' | ||
name?: string | ||
directory?: string | ||
path?: string | ||
} | ||
@@ -16,0 +16,0 @@ } |
@@ -17,4 +17,4 @@ import * as fs from 'fs' | ||
*/ | ||
public create(directory: string, options: Options): Promise<string> { | ||
const fileParts = new FileParts(directory) | ||
public create(path: string, options: Options): Promise<string> { | ||
const fileParts = new FileParts(path) | ||
@@ -25,5 +25,5 @@ const archiveData = { | ||
const outputLocation = this.getOutputDirectory(options) | ||
const outputLocation = this.getOutputPath(options) | ||
const getSourceBuffer = (): Buffer => fs.readFileSync(directory) | ||
const getSourceBuffer = (): Buffer => fs.readFileSync(path) | ||
@@ -57,6 +57,6 @@ const createZip = (sourceBuffer: Buffer): Promise<void> => { | ||
*/ | ||
public createBulk(directories: string[], options: Options): Promise<string> { | ||
const outputLocation = this.getOutputDirectory(options) | ||
public createBulk(paths: string[], options: Options): Promise<string> { | ||
const outputLocation = this.getOutputPath(options) | ||
const mapToFileParts = () => directories.map((directory: string) => new FileParts(directory)) | ||
const mapToFileParts = () => paths.map((path: string) => new FileParts(path)) | ||
@@ -70,3 +70,3 @@ const appendToZIP = (fileParts: FileParts[]) => { | ||
fileParts.forEach((filePart: FileParts) => { | ||
const sourceBuffer = fs.readFileSync(filePart.getDirectory()) | ||
const sourceBuffer = fs.readFileSync(filePart.getPath()) | ||
const archiveData = { | ||
@@ -96,7 +96,7 @@ name: `${filePart.getName()}.${filePart.getExtension()}` | ||
/** | ||
* Returns the output directory configured with specified options or defaults | ||
* Returns the output path configured with specified options or defaults | ||
*/ | ||
private getOutputDirectory(options: Options): string { | ||
private getOutputPath(options: Options): string { | ||
const outputName = options?.output?.name ?? uuid.v4() | ||
const outputDirectory = options?.output?.directory ?? os.tmpdir() | ||
const outputDirectory = options?.output?.path ?? os.tmpdir() | ||
@@ -103,0 +103,0 @@ return `${outputDirectory}/${outputName}.zip` |
@@ -6,3 +6,3 @@ import { FileParts } from '../../../../src/libs/FileParts' | ||
const fileExtension = 'txt' | ||
const directory = `/some/path/to/${fileName}.${fileExtension}` | ||
const path = `/some/path/to/${fileName}.${fileExtension}` | ||
@@ -12,11 +12,11 @@ let fileParts: FileParts | ||
beforeEach(() => { | ||
fileParts = new FileParts(directory) | ||
fileParts = new FileParts(path) | ||
}) | ||
describe('#constructor', () => { | ||
it('throws a `ZipsterError` when the directory is malformed', () => { | ||
it('throws a `ZipsterError` when the path is malformed', () => { | ||
try { | ||
new FileParts('/malformed/directory') | ||
new FileParts('/malformed/path') | ||
} catch (error) { | ||
return error.message.should.deep.equal('Directory missing file name or file extension') | ||
return error.message.should.deep.equal('Path missing file name or file extension') | ||
} | ||
@@ -40,8 +40,8 @@ }) | ||
describe('#getDirectory', () => { | ||
it('returns the initial directory', () => { | ||
return fileParts.getDirectory() | ||
.should.deep.equal(directory) | ||
describe('#getPath', () => { | ||
it('returns the initial path', () => { | ||
return fileParts.getPath() | ||
.should.deep.equal(path) | ||
}) | ||
}) | ||
}) |
@@ -154,6 +154,6 @@ import * as fs from 'fs' | ||
name: 'custom', | ||
directory: '/foo/bar' | ||
path: '/foo/bar' | ||
} | ||
} | ||
const expectedDirectory = `${options.output.directory}/${options.output.name}.zip` | ||
const expectedDirectory = `${options.output.path}/${options.output.name}.zip` | ||
@@ -160,0 +160,0 @@ readFileSync.returns(buffer) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18448
40