Compare commits

..

No commits in common. "master" and "v4.0.30" have entirely different histories.

13 changed files with 1074 additions and 1092 deletions

View File

@ -1,55 +0,0 @@
# Changelog
## 2024-10-13 - 4.0.39 - fix(core)
Fix dependencies and update documentation.
- Ensure package uses the latest dependencies
- Reviewed and grouped imports in TypeScript files
- Updated readme with advanced usage examples
## 2024-10-13 - 4.0.38 - fix(dependencies)
Update dependencies to latest versions
- Updated @push.rocks/smartfile to version 11.0.21
- Updated @push.rocks/smartpromise to version 4.0.4
- Updated @push.rocks/smartstream to version 3.0.46
- Updated @push.rocks/smarturl to version 3.1.0
- Updated file-type to version 19.5.0
- Updated @git.zone/tsbuild to version 2.1.84
- Updated @git.zone/tsrun to version 1.2.49
- Updated @push.rocks/tapbundle to version 5.3.0
## 2024-06-08 - 4.0.24 to 4.0.37 - Fixes and Updates
Core updates and bug fixes were implemented in versions 4.0.24 through 4.0.37.
- Repeated core updates and fixes applied consistently across multiple versions.
## 2024-06-06 - 4.0.22 to 4.0.23 - Descriptions and Fixes Updates
Efforts to update documentation and core features.
- "update description" in 4.0.22
- Updates to `tsconfig` and `npmextra.json` were performed.
- Ongoing core fixes.
## 2023-11-06 - 4.0.0 - Major Update with Breaking Changes
Introduction of significant updates and breaking changes.
- Transition to new version 4.0.0 with core updates.
- Break in compatibility due to major structural changes with core functionalities.
## 2023-07-11 - 3.0.6 - Organizational Changes
Structural reorganization and updates to the organization schema.
- Switch to new organizational schema implemented.
## 2022-04-04 - 3.0.0 - Build Updates and Breaking Changes
Major build update introducing breaking changes.
- Introduction of ESM structure with breaking changes.
## 2016-01-18 - 0.0.0 to 1.0.0 - Initial Development and Launch
Initial software development and establishment of core features.
- Project set-up including Travis CI integration.
- Launch of the first full version with code restructuring.
- Added callback support.

1
dist_ts/index.d.ts vendored
View File

@ -1,4 +1,3 @@
export * from './classes.smartarchive.js';
export * from './classes.tartools.js';
export * from './classes.ziptools.js';
export * from './classes.gziptools.js';

View File

@ -1,5 +1,4 @@
export * from './classes.smartarchive.js';
export * from './classes.tartools.js';
export * from './classes.ziptools.js';
export * from './classes.gziptools.js';
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLDJCQUEyQixDQUFDO0FBQzFDLGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyx1QkFBdUIsQ0FBQztBQUN0QyxjQUFjLHdCQUF3QixDQUFDIn0=
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLDJCQUEyQixDQUFDO0FBQzFDLGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyx1QkFBdUIsQ0FBQyJ9

View File

@ -18,12 +18,8 @@
"decompression",
"zip",
"tar",
"gzip",
"bzip2",
"file extraction",
"file creation",
"data analysis",
"file stream"
"gzip"
]
}
},

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartarchive",
"version": "4.0.39",
"version": "4.0.30",
"description": "A library for working with archive files, providing utilities for compressing and decompressing data.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
@ -22,25 +22,25 @@
"homepage": "https://code.foss.global/push.rocks/smartarchive",
"dependencies": {
"@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartfile": "^11.0.21",
"@push.rocks/smartfile": "^11.0.20",
"@push.rocks/smartpath": "^5.0.18",
"@push.rocks/smartpromise": "^4.0.4",
"@push.rocks/smartpromise": "^4.0.3",
"@push.rocks/smartrequest": "^2.0.22",
"@push.rocks/smartrx": "^3.0.7",
"@push.rocks/smartstream": "^3.0.46",
"@push.rocks/smartstream": "^3.0.44",
"@push.rocks/smartunique": "^3.0.9",
"@push.rocks/smarturl": "^3.1.0",
"@push.rocks/smarturl": "^3.0.7",
"@types/tar-stream": "^3.1.3",
"fflate": "^0.8.2",
"file-type": "^19.5.0",
"file-type": "^19.0.0",
"tar-stream": "^3.1.7",
"through": "^2.3.8"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.84",
"@git.zone/tsrun": "^1.2.49",
"@git.zone/tsbuild": "^2.1.80",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.90",
"@push.rocks/tapbundle": "^5.3.0"
"@push.rocks/tapbundle": "^5.0.23"
},
"private": false,
"files": [
@ -64,11 +64,7 @@
"decompression",
"zip",
"tar",
"gzip",
"bzip2",
"file extraction",
"file creation",
"data analysis",
"file stream"
"gzip"
]
}

1799
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

224
readme.md
View File

@ -1,10 +1,9 @@
# @push.rocks/smartarchive
`@push.rocks/smartarchive` is a powerful library designed for managing archive files. It provides utilities for compressing and decompressing data in various formats such as zip, tar, gzip, and bzip2. This library aims to simplify the process of handling archive files, making it an ideal choice for projects that require manipulation of archived data.
work with archives
## Install
To install `@push.rocks/smartarchive`, you can either use npm or yarn. Run one of the following commands in your project directory:
To install `@push.rocks/smartarchive`, you need to use npm or yarn. Run either of the following commands in your project directory:
```shell
npm install @push.rocks/smartarchive --save
@ -19,9 +18,10 @@ yarn add @push.rocks/smartarchive
This will add `@push.rocks/smartarchive` to your project's dependencies.
## Usage
`@push.rocks/smartarchive` provides an easy-to-use API for extracting, creating, and analyzing archive files. Below, we'll cover how to get started and explore various features of the module.
### Importing SmartArchive
`@push.rocks/smartarchive` is a powerful module designed to simplify the process of working with archive files such as zip, tar, gzip, and more. It provides an easy-to-use API for extracting, creating, and analyzing archives, making it an ideal choice for projects that require manipulation of archive files.
### Getting Started
First, import `SmartArchive` from `@push.rocks/smartarchive` using ESM syntax:
@ -31,11 +31,9 @@ import { SmartArchive } from '@push.rocks/smartarchive';
### Extracting Archive Files
You can extract archive files from different sources using `SmartArchive.fromArchiveUrl`, `SmartArchive.fromArchiveFile`, and `SmartArchive.fromArchiveStream`. Here's an example of extracting an archive from a URL:
To extract an archive file, you can use `SmartArchive.fromArchiveUrl`, `SmartArchive.fromArchiveFile`, or `SmartArchive.fromArchiveStream` methods depending on the source of your archive. Here's an example of extracting an archive from a URL:
```typescript
import { SmartArchive } from '@push.rocks/smartarchive';
async function extractArchiveFromURL() {
const url = 'https://example.com/archive.zip';
const targetDir = '/path/to/extract';
@ -45,37 +43,35 @@ async function extractArchiveFromURL() {
console.log('Archive extracted successfully.');
}
extractArchiveFromURL();
```
### Extracting an Archive from a File
### Creating Archive Files
Similarly, you can extract an archive from a local file:
Creating archive files such as zip or tar.gz is straightforward with `smartarchive`. At the moment, you'll prepare the contents programmatically and then compress them. Detailed support for creating archives will be covered in future updates.
### Analyzing Archive Files
Analyzing the content of archives without extracting them can be useful in various scenarios, such as when you need to inspect the archive's content before deciding to extract it. Here's how you might analyze an archive:
```typescript
import { SmartArchive } from '@push.rocks/smartarchive';
async function analyzeArchive() {
const url = 'https://example.com/archive.zip';
async function extractArchiveFromFile() {
const filePath = '/path/to/archive.zip';
const targetDir = '/path/to/extract';
const archive = await SmartArchive.fromArchiveUrl(url);
const analysisResult = await archive.analyzeContent();
const archive = await SmartArchive.fromArchiveFile(filePath);
await archive.exportToFs(targetDir);
console.log('Archive extracted successfully.');
console.log(analysisResult); // Outputs details about the archive content
}
extractArchiveFromFile();
```
### Stream-Based Extraction
Note: Replace `analyzeContent` with the appropriate method calls as per your implementation or update, as `smartarchive` provides foundational classes and methods for interaction with archive files but does not directly implement an `analyzeContent` method by default.
For larger files, you might prefer a streaming approach to prevent high memory consumption. Heres an example:
### Stream Operations
`smartarchive` offers streaming operations, allowing you to work with large archives efficiently. Here's an example of using streams to extract an archive:
```typescript
import { SmartArchive } from '@push.rocks/smartarchive';
import { createReadStream } from 'fs';
import { createReadStream, createWriteStream } from 'fs';
async function extractArchiveUsingStream() {
const archiveStream = createReadStream('/path/to/archive.zip');
@ -84,183 +80,15 @@ async function extractArchiveUsingStream() {
extractionStream.pipe(createWriteStream('/path/to/destination'));
}
extractArchiveUsingStream();
```
### Analyzing Archive Files
### Conclusion
Sometimes, you may need to inspect the contents of an archive before extracting it. The following example shows how to analyze an archive:
`@push.rocks/smartarchive` simplifies the process of working with various archive formats in JavaScript and TypeScript projects. By providing an easy-to-use API for common archive operations, it enables developers to integrate archive manipulation features into their applications efficiently.
```typescript
import { SmartArchive } from '@push.rocks/smartarchive';
Remember, the examples provided here are to give you a starting point. Depending on your specific use case, you may need to adjust these examples to fit your project's requirements. Always refer to the latest documentation for the most current information and methods available in `@push.rocks/smartarchive`.
async function analyzeArchive() {
const filePath = '/path/to/archive.zip';
const archive = await SmartArchive.fromArchiveFile(filePath);
const analysisResult = await archive.analyzeContent();
console.log(analysisResult); // Outputs details about the archive content
}
analyzeArchive();
```
### Creating Archive Files
Creating an archive file is straightforward. Here we demonstrate creating a tar.gz archive:
```typescript
import { SmartArchive } from '@push.rocks/smartarchive';
async function createTarGzArchive() {
const archive = new SmartArchive();
// Add directories and files
archive.addedDirectories.push('/path/to/directory1');
archive.addedFiles.push('/path/to/file1.txt');
// Export as tar.gz
const tarGzStream = await archive.exportToTarGzStream();
// Save to filesystem or handle as needed
tarGzStream.pipe(createWriteStream('/path/to/destination.tar.gz'));
}
createTarGzArchive();
```
### Stream Operations
Here's an example of using `smartarchive`'s streaming capabilities:
```typescript
import { createReadStream, createWriteStream } from 'fs';
import { SmartArchive } from '@push.rocks/smartarchive';
async function extractArchiveUsingStreams() {
const archiveStream = createReadStream('/path/to/archive.zip');
const archive = await SmartArchive.fromArchiveStream(archiveStream);
const extractionStream = await archive.exportToStreamOfStreamFiles();
extractionStream.pipe(createWriteStream('/path/to/extracted'));
}
extractArchiveUsingStreams();
```
### Advanced Decompression Usage
`smartarchive` supports multiple compression formats. It also provides detailed control over the decompression processes:
- For ZIP files, `ZipTools` handles decompression using the `fflate` library.
- For TAR files, `TarTools` uses `tar-stream`.
- For GZIP files, `GzipTools` provides a `CompressGunzipTransform` and `DecompressGunzipTransform`.
- For BZIP2 files, `Bzip2Tools` utilizes custom streaming decompression.
Example: Working with a GZIP-compressed archive:
```typescript
import { createReadStream, createWriteStream } from 'fs';
import { SmartArchive } from '@push.rocks/smartarchive';
async function decompressGzipArchive() {
const filePath = '/path/to/archive.gz';
const targetDir = '/path/to/extract';
const archive = await SmartArchive.fromArchiveFile(filePath);
await archive.exportToFs(targetDir);
console.log('GZIP archive decompressed successfully.');
}
decompressGzipArchive();
```
### Advancing with Custom Decompression Streams
You can inject custom decompression streams where needed:
```typescript
import { createReadStream, createWriteStream } from 'fs';
import { SmartArchive, GzipTools } from '@push.rocks/smartarchive';
async function customDecompression() {
const filePath = '/path/to/archive.gz';
const targetDir = '/path/to/extract';
const archive = await SmartArchive.fromArchiveFile(filePath);
const gzipTools = new GzipTools();
const decompressionStream = gzipTools.getDecompressionStream();
const archiveStream = await archive.getArchiveStream();
archiveStream.pipe(decompressionStream).pipe(createWriteStream(targetDir));
console.log('Custom GZIP decompression successful.');
}
customDecompression();
```
### Custom Pack and Unpack Tar
When dealing with tar archives, you may need to perform custom packing and unpacking:
```typescript
import { SmartArchive, TarTools } from '@push.rocks/smartarchive';
import { createWriteStream } from 'fs';
async function customTarOperations() {
const tarTools = new TarTools();
// Packing a directory into a tar stream
const packStream = await tarTools.packDirectory('/path/to/directory');
packStream.pipe(createWriteStream('/path/to/archive.tar'));
// Extracting files from a tar stream
const extractStream = tarTools.getDecompressionStream();
createReadStream('/path/to/archive.tar').pipe(extractStream).on('entry', (header, stream, next) => {
const writeStream = createWriteStream(`/path/to/extract/${header.name}`);
stream.pipe(writeStream);
stream.on('end', next);
});
}
customTarOperations();
```
### Extract and Analyze All-in-One
To extract and simultaneously analyze archive content:
```typescript
import { createReadStream, createWriteStream } from 'fs';
import { SmartArchive } from '@push.rocks/smartarchive';
async function extractAndAnalyze() {
const filePath = '/path/to/archive.zip';
const targetDir = '/path/to/extract';
const archive = await SmartArchive.fromArchiveFile(filePath);
const analyzedStream = archive.archiveAnalyzer.getAnalyzedStream();
const extractionStream = await archive.exportToStreamOfStreamFiles();
analyzedStream.pipe(extractionStream).pipe(createWriteStream(targetDir));
analyzedStream.on('data', (chunk) => {
console.log(JSON.stringify(chunk, null, 2));
});
}
extractAndAnalyze();
```
### Final Words
These examples demonstrate various use cases for `@push.rocks/smartarchive`. Depending on your specific project requirements, you can adapt these examples to suit your needs. Always refer to the latest documentation for the most current information and methods available in `@push.rocks/smartarchive`.
For more information and API references, check the official [`@push.rocks/smartarchive` GitHub repository](https://code.foss.global/push.rocks/smartarchive).
For more information and API references, check the official [`@push.rocks/smartarchive` GitHub repository](https://github.com/pushrocks/smartarchive).
## License and Legal Information

View File

@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @push.rocks/commitinfo
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartarchive',
version: '4.0.39',
version: '4.0.30',
description: 'A library for working with archive files, providing utilities for compressing and decompressing data.'
}

View File

@ -43,7 +43,10 @@ export class DecompressGunzipTransform extends plugins.stream.Transform {
export class GzipTools {
constructor() {
smartArchiveRef: SmartArchive;
constructor(smartArchiveRefArg: SmartArchive) {
this.smartArchiveRef = smartArchiveRefArg;
}
public getCompressionStream() {

View File

@ -33,10 +33,10 @@ export class SmartArchive {
}
// INSTANCE
public tarTools = new TarTools();
public zipTools = new ZipTools();
public gzipTools = new GzipTools();
public gzipTools = new GzipTools(this);
public bzip2Tools = new Bzip2Tools(this);
public tarTools = new TarTools(this);
public zipTools = new ZipTools(this);
public archiveAnalyzer = new ArchiveAnalyzer(this);
public sourceUrl: string;

View File

@ -3,7 +3,11 @@ import * as plugins from './plugins.js';
export class TarTools {
// INSTANCE
constructor() {}
smartArchiveRef: SmartArchive;
constructor(smartArchiveRefArg: SmartArchive) {
this.smartArchiveRef = smartArchiveRefArg;
}
// packing
public async addFileToPack(
@ -21,17 +25,12 @@ export class TarTools {
}
): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let fileName: string | null = null;
if (optionsArg.fileName) {
fileName = optionsArg.fileName;
} else if (optionsArg.content instanceof plugins.smartfile.SmartFile) {
fileName = (optionsArg.content as plugins.smartfile.SmartFile).relative;
} else if (optionsArg.content instanceof plugins.smartfile.StreamFile) {
fileName = (optionsArg.content as plugins.smartfile.StreamFile).relativeFilePath;
} else if (optionsArg.filePath) {
fileName = optionsArg.filePath;
}
let fileName =
optionsArg.fileName || optionsArg.content instanceof plugins.smartfile.SmartFile
? (optionsArg.content as plugins.smartfile.SmartFile).relative
: null || optionsArg.content instanceof plugins.smartfile.StreamFile
? (optionsArg.content as plugins.smartfile.StreamFile).relativeFilePath
: null || optionsArg.filePath;
/**
* contentByteLength is used to set the size of the entry in the tar file
@ -91,7 +90,9 @@ export class TarTools {
);
content.pipe(entry);
resolve();
entry.on('end', () => {
resolve();
});
});
}
@ -107,7 +108,7 @@ export class TarTools {
const fileStat = await plugins.smartfile.fs.stat(absolutePath);
await this.addFileToPack(pack, {
byteLength: fileStat.size,
filePath: absolutePath,
filePath: filePath,
fileName: filePath,
content: plugins.smartfile.fsStream.createReadStream(absolutePath),
});

View File

@ -61,7 +61,10 @@ export class CompressZipTransform extends plugins.stream.Transform {
}
export class ZipTools {
constructor() {
smartArchiveRef: SmartArchive;
constructor(smartArchiveRefArg: SmartArchive) {
this.smartArchiveRef = smartArchiveRefArg;
}
public getCompressionStream() {

View File

@ -1,4 +1,3 @@
export * from './classes.smartarchive.js';
export * from './classes.tartools.js';
export * from './classes.ziptools.js';
export * from './classes.gziptools.js';