Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
ed5f590b5f | |||
a32ed0facd | |||
b5a3793ed5 | |||
be1bc958d8 | |||
21434622dd | |||
50c0368ac7 | |||
78b3fcfd83 | |||
61caf51f4e | |||
be4e2cdae7 | |||
1cb8331666 | |||
aa203c5ab2 | |||
87aedd5ef5 | |||
64431703b5 | |||
120fd0b321 | |||
e6192c418e | |||
00a039936f | |||
e03c3a62b1 | |||
538eced73b | |||
fe8a5713f0 | |||
37e8a1d0f7 | |||
5143cd098d | |||
4d5ea812af | |||
500ef01ded | |||
3196a02835 | |||
de1c46ed0a | |||
b4c7b065fa | |||
93da11a951 | |||
ecd7f6d419 | |||
a3ecfe4d99 | |||
f99f6d96c5 | |||
b4be70f43a |
BIN
.serena/cache/typescript/document_symbols_cache_v23-06-25.pkl
vendored
Normal file
BIN
.serena/cache/typescript/document_symbols_cache_v23-06-25.pkl
vendored
Normal file
Binary file not shown.
68
.serena/project.yml
Normal file
68
.serena/project.yml
Normal file
@@ -0,0 +1,68 @@
|
||||
# language of the project (csharp, python, rust, java, typescript, go, cpp, or ruby)
|
||||
# * For C, use cpp
|
||||
# * For JavaScript, use typescript
|
||||
# Special requirements:
|
||||
# * csharp: Requires the presence of a .sln file in the project folder.
|
||||
language: typescript
|
||||
|
||||
# whether to use the project's gitignore file to ignore files
|
||||
# Added on 2025-04-07
|
||||
ignore_all_files_in_gitignore: true
|
||||
# list of additional paths to ignore
|
||||
# same syntax as gitignore, so you can use * and **
|
||||
# Was previously called `ignored_dirs`, please update your config if you are using that.
|
||||
# Added (renamed) on 2025-04-07
|
||||
ignored_paths: []
|
||||
|
||||
# whether the project is in read-only mode
|
||||
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
|
||||
# Added on 2025-04-18
|
||||
read_only: false
|
||||
|
||||
|
||||
# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.
|
||||
# Below is the complete list of tools for convenience.
|
||||
# To make sure you have the latest list of tools, and to view their descriptions,
|
||||
# execute `uv run scripts/print_tool_overview.py`.
|
||||
#
|
||||
# * `activate_project`: Activates a project by name.
|
||||
# * `check_onboarding_performed`: Checks whether project onboarding was already performed.
|
||||
# * `create_text_file`: Creates/overwrites a file in the project directory.
|
||||
# * `delete_lines`: Deletes a range of lines within a file.
|
||||
# * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
|
||||
# * `execute_shell_command`: Executes a shell command.
|
||||
# * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
|
||||
# * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
|
||||
# * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
|
||||
# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
|
||||
# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
|
||||
# * `initial_instructions`: Gets the initial instructions for the current project.
|
||||
# Should only be used in settings where the system prompt cannot be set,
|
||||
# e.g. in clients you have no control over, like Claude Desktop.
|
||||
# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
|
||||
# * `insert_at_line`: Inserts content at a given line in a file.
|
||||
# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
|
||||
# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
|
||||
# * `list_memories`: Lists memories in Serena's project-specific memory store.
|
||||
# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
|
||||
# * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
|
||||
# * `read_file`: Reads a file within the project directory.
|
||||
# * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
|
||||
# * `remove_project`: Removes a project from the Serena configuration.
|
||||
# * `replace_lines`: Replaces a range of lines within a file with new content.
|
||||
# * `replace_symbol_body`: Replaces the full definition of a symbol.
|
||||
# * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
|
||||
# * `search_for_pattern`: Performs a search for a pattern in the project.
|
||||
# * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
|
||||
# * `switch_modes`: Activates modes by providing a list of their names
|
||||
# * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
|
||||
# * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
|
||||
# * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
|
||||
# * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
|
||||
excluded_tools: []
|
||||
|
||||
# initial prompt for the project. It will always be given to the LLM upon activating the project
|
||||
# (contrary to the memories, which are loaded on demand).
|
||||
initial_prompt: ""
|
||||
|
||||
project_name: "smartarchive"
|
63
changelog.md
Normal file
63
changelog.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Changelog
|
||||
|
||||
## 2025-08-18 - 4.1.0 - feat(classes.smartarchive)
|
||||
Support URL web streams, add recursive archive unpacking and filesystem export, and improve ZIP decompression robustness
|
||||
|
||||
- ts/classes.smartarchive.ts: add exportToFs(targetDir, fileName?) to write extracted StreamFile objects to the filesystem (ensures directories, logs relative paths, waits for write completion).
|
||||
- ts/classes.smartarchive.ts: implement exportToStreamOfStreamFiles with recursive unpacking pipeline that handles application/x-tar (tar-stream Extract), application/zip (fflate unzip), nested archives and StreamIntake for StreamFile results.
|
||||
- ts/classes.smartarchive.ts: improve getArchiveStream() for URL sources by using SmartRequest.create().url(...).get() and converting the returned Web stream into a Node Readable stream.
|
||||
- ts/classes.ziptools.ts: make ZIP decompression writeFunction more robust — accept non-Buffer chunks, coerce to Buffer before pushing to fflate.Unzip, and loosen the writeFunction typing to handle incoming ArrayBuffer-like data.
|
||||
|
||||
## 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.
|
3
dist_ts/index.d.ts
vendored
3
dist_ts/index.d.ts
vendored
@@ -1 +1,4 @@
|
||||
export * from './classes.smartarchive.js';
|
||||
export * from './classes.tartools.js';
|
||||
export * from './classes.ziptools.js';
|
||||
export * from './classes.gziptools.js';
|
||||
|
@@ -1,2 +1,5 @@
|
||||
export * from './classes.smartarchive.js';
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLDJCQUEyQixDQUFDIn0=
|
||||
export * from './classes.tartools.js';
|
||||
export * from './classes.ziptools.js';
|
||||
export * from './classes.gziptools.js';
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLDJCQUEyQixDQUFDO0FBQzFDLGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyx1QkFBdUIsQ0FBQztBQUN0QyxjQUFjLHdCQUF3QixDQUFDIn0=
|
@@ -18,8 +18,12 @@
|
||||
"decompression",
|
||||
"zip",
|
||||
"tar",
|
||||
"gzip",
|
||||
"bzip2",
|
||||
"gzip"
|
||||
"file extraction",
|
||||
"file creation",
|
||||
"data analysis",
|
||||
"file stream"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
38
package.json
38
package.json
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@push.rocks/smartarchive",
|
||||
"version": "4.0.25",
|
||||
"version": "4.1.0",
|
||||
"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",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"test": "(tstest test/ --verbose)",
|
||||
"build": "tsbuild --web --allowimplicitany",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
@@ -22,25 +22,24 @@
|
||||
"homepage": "https://code.foss.global/push.rocks/smartarchive",
|
||||
"dependencies": {
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartfile": "^11.0.20",
|
||||
"@push.rocks/smartpath": "^5.0.18",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/smartrequest": "^2.0.22",
|
||||
"@push.rocks/smartrx": "^3.0.7",
|
||||
"@push.rocks/smartstream": "^3.0.44",
|
||||
"@push.rocks/smartfile": "^11.2.7",
|
||||
"@push.rocks/smartpath": "^6.0.0",
|
||||
"@push.rocks/smartpromise": "^4.2.3",
|
||||
"@push.rocks/smartrequest": "^4.2.2",
|
||||
"@push.rocks/smartrx": "^3.0.10",
|
||||
"@push.rocks/smartstream": "^3.2.5",
|
||||
"@push.rocks/smartunique": "^3.0.9",
|
||||
"@push.rocks/smarturl": "^3.0.7",
|
||||
"@types/tar-stream": "^3.1.3",
|
||||
"@push.rocks/smarturl": "^3.1.0",
|
||||
"@types/tar-stream": "^3.1.4",
|
||||
"fflate": "^0.8.2",
|
||||
"file-type": "^19.0.0",
|
||||
"file-type": "^21.0.0",
|
||||
"tar-stream": "^3.1.7",
|
||||
"through": "^2.3.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.80",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@push.rocks/tapbundle": "^5.0.23"
|
||||
"@git.zone/tsbuild": "^2.6.6",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^2.3.4"
|
||||
},
|
||||
"private": false,
|
||||
"files": [
|
||||
@@ -64,7 +63,12 @@
|
||||
"decompression",
|
||||
"zip",
|
||||
"tar",
|
||||
"gzip",
|
||||
"bzip2",
|
||||
"gzip"
|
||||
]
|
||||
"file extraction",
|
||||
"file creation",
|
||||
"data analysis",
|
||||
"file stream"
|
||||
],
|
||||
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748"
|
||||
}
|
||||
|
7979
pnpm-lock.yaml
generated
7979
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
4
pnpm-workspace.yaml
Normal file
4
pnpm-workspace.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
onlyBuiltDependencies:
|
||||
- esbuild
|
||||
- mongodb-memory-server
|
||||
- puppeteer
|
228
readme.md
228
readme.md
@@ -1,9 +1,10 @@
|
||||
# @push.rocks/smartarchive
|
||||
work with archives
|
||||
|
||||
`@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.
|
||||
|
||||
## Install
|
||||
|
||||
To install `@push.rocks/smartarchive`, you need to use npm or yarn. Run either of the following commands in your project directory:
|
||||
To install `@push.rocks/smartarchive`, you can either use npm or yarn. Run one of the following commands in your project directory:
|
||||
|
||||
```shell
|
||||
npm install @push.rocks/smartarchive --save
|
||||
@@ -18,10 +19,9 @@ 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.
|
||||
|
||||
`@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
|
||||
### Importing SmartArchive
|
||||
|
||||
First, import `SmartArchive` from `@push.rocks/smartarchive` using ESM syntax:
|
||||
|
||||
@@ -31,9 +31,11 @@ import { SmartArchive } from '@push.rocks/smartarchive';
|
||||
|
||||
### Extracting Archive Files
|
||||
|
||||
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:
|
||||
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:
|
||||
|
||||
```typescript
|
||||
import { SmartArchive } from '@push.rocks/smartarchive';
|
||||
|
||||
async function extractArchiveFromURL() {
|
||||
const url = 'https://example.com/archive.zip';
|
||||
const targetDir = '/path/to/extract';
|
||||
@@ -43,35 +45,37 @@ async function extractArchiveFromURL() {
|
||||
|
||||
console.log('Archive extracted successfully.');
|
||||
}
|
||||
|
||||
extractArchiveFromURL();
|
||||
```
|
||||
|
||||
### Creating Archive Files
|
||||
### Extracting an Archive from a 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:
|
||||
Similarly, you can extract an archive from a local file:
|
||||
|
||||
```typescript
|
||||
async function analyzeArchive() {
|
||||
const url = 'https://example.com/archive.zip';
|
||||
|
||||
const archive = await SmartArchive.fromArchiveUrl(url);
|
||||
const analysisResult = await archive.analyzeContent();
|
||||
|
||||
console.log(analysisResult); // Outputs details about the archive content
|
||||
import { SmartArchive } from '@push.rocks/smartarchive';
|
||||
|
||||
async function extractArchiveFromFile() {
|
||||
const filePath = '/path/to/archive.zip';
|
||||
const targetDir = '/path/to/extract';
|
||||
|
||||
const archive = await SmartArchive.fromArchiveFile(filePath);
|
||||
await archive.exportToFs(targetDir);
|
||||
|
||||
console.log('Archive extracted successfully.');
|
||||
}
|
||||
|
||||
extractArchiveFromFile();
|
||||
```
|
||||
|
||||
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.
|
||||
### Stream-Based Extraction
|
||||
|
||||
### 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:
|
||||
For larger files, you might prefer a streaming approach to prevent high memory consumption. Here’s an example:
|
||||
|
||||
```typescript
|
||||
import { createReadStream, createWriteStream } from 'fs';
|
||||
import { SmartArchive } from '@push.rocks/smartarchive';
|
||||
import { createReadStream } from 'fs';
|
||||
|
||||
async function extractArchiveUsingStream() {
|
||||
const archiveStream = createReadStream('/path/to/archive.zip');
|
||||
@@ -80,15 +84,183 @@ async function extractArchiveUsingStream() {
|
||||
|
||||
extractionStream.pipe(createWriteStream('/path/to/destination'));
|
||||
}
|
||||
|
||||
extractArchiveUsingStream();
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
### Analyzing Archive Files
|
||||
|
||||
`@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.
|
||||
Sometimes, you may need to inspect the contents of an archive before extracting it. The following example shows how to analyze an archive:
|
||||
|
||||
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`.
|
||||
```typescript
|
||||
import { SmartArchive } from '@push.rocks/smartarchive';
|
||||
|
||||
For more information and API references, check the official [`@push.rocks/smartarchive` GitHub repository](https://github.com/pushrocks/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).
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
|
11
test/test.ts
11
test/test.ts
@@ -1,4 +1,4 @@
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
@@ -20,11 +20,10 @@ tap.preTask('should prepare .nogit dir', async () => {
|
||||
});
|
||||
|
||||
tap.preTask('should prepare downloads', async (tools) => {
|
||||
const downloadedFile: Buffer = (
|
||||
await plugins.smartrequest.getBinary(
|
||||
'https://verdaccio.lossless.digital/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz'
|
||||
)
|
||||
).body;
|
||||
const response = await plugins.smartrequest.SmartRequest.create()
|
||||
.url('https://verdaccio.lossless.digital/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz')
|
||||
.get();
|
||||
const downloadedFile: Buffer = Buffer.from(await response.arrayBuffer());
|
||||
await plugins.smartfile.memory.toFs(
|
||||
downloadedFile,
|
||||
plugins.path.join(testPaths.nogitDir, 'test.tgz')
|
||||
|
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartarchive',
|
||||
version: '4.0.25',
|
||||
version: '4.1.0',
|
||||
description: 'A library for working with archive files, providing utilities for compressing and decompressing data.'
|
||||
}
|
||||
|
@@ -43,10 +43,7 @@ export class DecompressGunzipTransform extends plugins.stream.Transform {
|
||||
|
||||
|
||||
export class GzipTools {
|
||||
smartArchiveRef: SmartArchive;
|
||||
|
||||
constructor(smartArchiveRefArg: SmartArchive) {
|
||||
this.smartArchiveRef = smartArchiveRefArg;
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public getCompressionStream() {
|
||||
|
@@ -33,10 +33,10 @@ export class SmartArchive {
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public gzipTools = new GzipTools(this);
|
||||
public tarTools = new TarTools();
|
||||
public zipTools = new ZipTools();
|
||||
public gzipTools = new GzipTools();
|
||||
public bzip2Tools = new Bzip2Tools(this);
|
||||
public tarTools = new TarTools(this);
|
||||
public zipTools = new ZipTools(this);
|
||||
public archiveAnalyzer = new ArchiveAnalyzer(this);
|
||||
|
||||
public sourceUrl: string;
|
||||
@@ -60,7 +60,12 @@ export class SmartArchive {
|
||||
return this.sourceStream;
|
||||
}
|
||||
if (this.sourceUrl) {
|
||||
const urlStream = await plugins.smartrequest.getStream(this.sourceUrl);
|
||||
const response = await plugins.smartrequest.SmartRequest.create()
|
||||
.url(this.sourceUrl)
|
||||
.get();
|
||||
const webStream = response.stream();
|
||||
// @ts-ignore - Web stream to Node.js stream conversion
|
||||
const urlStream = plugins.stream.Readable.fromWeb(webStream);
|
||||
return urlStream;
|
||||
}
|
||||
if (this.sourceFilePath) {
|
||||
|
@@ -3,11 +3,7 @@ import * as plugins from './plugins.js';
|
||||
|
||||
export class TarTools {
|
||||
// INSTANCE
|
||||
smartArchiveRef: SmartArchive;
|
||||
|
||||
constructor(smartArchiveRefArg: SmartArchive) {
|
||||
this.smartArchiveRef = smartArchiveRefArg;
|
||||
}
|
||||
constructor() {}
|
||||
|
||||
// packing
|
||||
public async addFileToPack(
|
||||
@@ -25,12 +21,17 @@ export class TarTools {
|
||||
}
|
||||
): Promise<void> {
|
||||
return new Promise<void>(async (resolve, reject) => {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* contentByteLength is used to set the size of the entry in the tar file
|
||||
@@ -55,6 +56,22 @@ export class TarTools {
|
||||
contentByteLength = fileStat.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* here we try to harmonize all kind of entries towards a readable stream
|
||||
*/
|
||||
let content: plugins.smartstream.stream.Readable;
|
||||
if (Buffer.isBuffer(optionsArg.content)) {
|
||||
content = plugins.smartstream.stream.Readable.from(optionsArg.content);
|
||||
} else if (typeof optionsArg.content === 'string') {
|
||||
content = plugins.smartstream.stream.Readable.from(Buffer.from(optionsArg.content));
|
||||
} else if (optionsArg.content instanceof plugins.smartfile.SmartFile) {
|
||||
content = plugins.smartstream.stream.Readable.from(optionsArg.content.contents);
|
||||
} else if (optionsArg.content instanceof plugins.smartfile.StreamFile) {
|
||||
content = await optionsArg.content.createReadStream();
|
||||
} else if (optionsArg.content instanceof plugins.smartstream.stream.Readable) {
|
||||
content = optionsArg.content;
|
||||
}
|
||||
|
||||
const entry = pack.entry(
|
||||
{
|
||||
name: fileName,
|
||||
@@ -73,23 +90,8 @@ export class TarTools {
|
||||
}
|
||||
);
|
||||
|
||||
let content: plugins.smartstream.stream.Readable;
|
||||
if (Buffer.isBuffer(optionsArg.content)) {
|
||||
content = plugins.smartstream.stream.Readable.from(optionsArg.content);
|
||||
} else if (typeof optionsArg.content === 'string') {
|
||||
content = plugins.smartstream.stream.Readable.from(Buffer.from(optionsArg.content));
|
||||
} else if (optionsArg.content instanceof plugins.smartfile.SmartFile) {
|
||||
content = plugins.smartstream.stream.Readable.from(optionsArg.content.contents);
|
||||
} else if (optionsArg.content instanceof plugins.smartfile.StreamFile) {
|
||||
content = await optionsArg.content.createReadStream();
|
||||
} else if (optionsArg.content instanceof plugins.smartstream.stream.Readable) {
|
||||
content = optionsArg.content;
|
||||
}
|
||||
|
||||
content.pipe(entry);
|
||||
entry.on('end', () => {
|
||||
resolve();
|
||||
});
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,11 +107,12 @@ export class TarTools {
|
||||
const fileStat = await plugins.smartfile.fs.stat(absolutePath);
|
||||
await this.addFileToPack(pack, {
|
||||
byteLength: fileStat.size,
|
||||
filePath: filePath,
|
||||
filePath: absolutePath,
|
||||
fileName: filePath,
|
||||
content: plugins.smartfile.fsStream.createReadStream(absolutePath),
|
||||
});
|
||||
}
|
||||
return pack;
|
||||
}
|
||||
|
||||
public async getPackStream() {
|
||||
|
@@ -19,9 +19,9 @@ class DecompressZipTransform extends plugins.smartstream.SmartDuplex<ArrayBuffer
|
||||
constructor() {
|
||||
super({
|
||||
objectMode: true,
|
||||
writeFunction: async (chunkArg: Buffer, streamtoolsArg) => {
|
||||
writeFunction: async (chunkArg, streamtoolsArg) => {
|
||||
this.streamtools? null : this.streamtools = streamtoolsArg;
|
||||
this.unzipper.push(chunkArg, false);
|
||||
this.unzipper.push(Buffer.isBuffer(chunkArg) ? chunkArg : Buffer.from(chunkArg), false);
|
||||
},
|
||||
finalFunction: async () => {
|
||||
this.unzipper.push(Buffer.from(''), true);
|
||||
@@ -61,10 +61,7 @@ export class CompressZipTransform extends plugins.stream.Transform {
|
||||
}
|
||||
|
||||
export class ZipTools {
|
||||
smartArchiveRef: SmartArchive;
|
||||
|
||||
constructor(smartArchiveRefArg: SmartArchive) {
|
||||
this.smartArchiveRef = smartArchiveRefArg;
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public getCompressionStream() {
|
||||
|
@@ -1 +1,4 @@
|
||||
export * from './classes.smartarchive.js';
|
||||
export * from './classes.tartools.js';
|
||||
export * from './classes.ziptools.js';
|
||||
export * from './classes.gziptools.js';
|
||||
|
Reference in New Issue
Block a user