Compare commits

..

25 Commits

Author SHA1 Message Date
0d50cdafbf 3.0.6 2022-06-07 18:04:35 +02:00
4b3c9c9269 fix(core): update 2022-06-07 18:04:35 +02:00
447a02b4c0 3.0.5 2022-06-07 17:11:13 +02:00
9e14d881ba fix(core): update 2022-06-07 17:11:13 +02:00
277a3fff41 3.0.4 2022-06-06 11:29:13 +02:00
fc107509ff fix(core): update 2022-06-06 11:29:13 +02:00
08d5461602 3.0.3 2022-06-06 11:17:57 +02:00
0b93067783 fix(core): update 2022-06-06 11:17:56 +02:00
f70177001b 3.0.2 2022-04-13 15:41:07 +02:00
232bb80bcb update 2022-04-04 19:50:42 +02:00
55e9287468 3.0.1 2022-04-04 16:28:45 +02:00
a71fdf805d fix build 2022-04-04 16:28:40 +02:00
69cf63c80a 3.0.0 2022-04-04 14:15:58 +02:00
14e823fbfd BREANKING CHANGE(core): switch to esm 2022-04-04 14:15:51 +02:00
abe1299203 2.0.4 2021-04-19 14:14:25 +00:00
99ce99795a fix(core): update 2021-04-19 14:14:24 +00:00
f6a54ead5d 2.0.3 2021-04-19 14:13:53 +00:00
cb48cfa948 fix(core): update 2021-04-19 14:13:53 +00:00
36a5c2480f 2.0.2 2021-04-19 12:15:24 +00:00
70a08fd92b fix(core): update 2021-04-19 12:15:23 +00:00
02a0646a49 2.0.1 2021-04-19 12:12:49 +00:00
17eda1e56a fix(core): update 2021-04-19 12:12:48 +00:00
ea6c514a40 2.0.0 2021-04-19 11:59:14 +00:00
ca3975abea 1.0.14 2021-04-19 11:53:49 +00:00
c405a83689 fix(core): update 2021-04-19 11:53:49 +00:00
16 changed files with 9173 additions and 10092 deletions

2
dist_ts/index.d.ts vendored
View File

@ -1 +1 @@
export * from './smartarchive.classes.smartarchive';
export * from './smartarchive.classes.smartarchive.js';

View File

@ -1,7 +1,2 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./smartarchive.classes.smartarchive"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLHlEQUFvRCJ9
export * from './smartarchive.classes.smartarchive.js';
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHdDQUF3QyxDQUFDIn0=

View File

@ -1,5 +1,30 @@
/// <reference types="node" resolution-mode="require"/>
import * as plugins from './smartarchive.plugins.js';
export declare class SmartArchive {
archiveDirectory: string;
constructor();
extractArchiveFromFilePath(filePathArg: string, targetDir: string): void;
/**
* extracts an archive from a given url
*/
extractArchiveFromUrlToFs(urlArg: string, targetDir: string): Promise<void>;
/**
* extracts an archive from a given filePath on disk
* @param filePathArg
* @param targetDir
*/
extractArchiveFromFilePathToFs(filePathArg: string, targetDir: string): Promise<void>;
/**
* extracts to Observable
*/
extractArchiveFromBufferToObservable(bufferArg: Buffer): Promise<plugins.smartrx.rxjs.ReplaySubject<plugins.smartfile.Smartfile>>;
/**
* extracts to Observable
*/
extractArchiveFromUrlToObservable(urlArg: string): Promise<plugins.smartrx.rxjs.ReplaySubject<plugins.smartfile.Smartfile>>;
extractArchiveFromUrlToStream(): Promise<void>;
extractArchiveFromFilePathToStream(): Promise<void>;
extractArchiveFromStreamToStream(): Promise<void>;
packFromStreamToStream(): Promise<void>;
packFromDirPathToStream(): Promise<void>;
packFromDirPathToFs(): Promise<void>;
}

View File

@ -1,21 +1,87 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = __importStar(require("./smartarchive.plugins"));
class SmartArchive {
import * as plugins from './smartarchive.plugins.js';
import * as paths from './smartarchive.paths.js';
export class SmartArchive {
constructor() { }
extractArchiveFromFilePath(filePathArg, targetDir) {
const parsedPath = plugins.path.parse(filePathArg);
switch (parsedPath.ext) {
}
/**
* extracts an archive from a given url
*/
async extractArchiveFromUrlToFs(urlArg, targetDir) {
const parsedPath = plugins.path.parse(urlArg);
const uniqueFileName = plugins.smartunique.uni() + parsedPath.ext;
plugins.smartfile.fs.ensureDir(paths.nogitDir); // TODO: totally remove caching needs
const downloadPath = plugins.path.join(paths.nogitDir, uniqueFileName);
const downloadedArchive = (await plugins.smartrequest.getBinary(urlArg)).body;
await plugins.smartfile.memory.toFs(downloadedArchive, downloadPath);
await this.extractArchiveFromFilePathToFs(downloadPath, targetDir);
await plugins.smartfile.fs.remove(downloadPath);
}
;
/**
* extracts an archive from a given filePath on disk
* @param filePathArg
* @param targetDir
*/
async extractArchiveFromFilePathToFs(filePathArg, targetDir) {
console.log(`extracting ${filePathArg}`);
}
/**
* extracts to Observable
*/
async extractArchiveFromBufferToObservable(bufferArg) {
const intake = new plugins.smartstream.StreamIntake();
const replaySubject = new plugins.smartrx.rxjs.ReplaySubject();
const readableStream = intake.getReadableStream();
const extractPipeStop = plugins.tarStream.extract();
extractPipeStop.on('entry', (header, stream, next) => {
let fileBuffer;
stream.on('data', (chunkArg) => {
if (!fileBuffer) {
fileBuffer = chunkArg;
}
else {
fileBuffer = Buffer.concat([fileBuffer, chunkArg]);
}
});
stream.on('end', () => {
replaySubject.next(new plugins.smartfile.Smartfile({
base: null,
contentBuffer: fileBuffer,
path: `${header.name}`
}));
next();
});
stream.resume();
});
extractPipeStop.on('finish', () => {
replaySubject.complete();
});
// lets run the stream
readableStream
.pipe(plugins.gunzipMaybe())
.pipe(extractPipeStop);
intake.pushData(bufferArg);
intake.signalEnd();
return replaySubject;
}
/**
* extracts to Observable
*/
async extractArchiveFromUrlToObservable(urlArg) {
const response = await plugins.smartrequest.getBinary(urlArg);
const replaySubject = this.extractArchiveFromBufferToObservable(response.body);
return replaySubject;
}
// TODO
async extractArchiveFromUrlToStream() {
}
// TODO
async extractArchiveFromFilePathToStream() { }
// TODO
async extractArchiveFromStreamToStream() { }
// TODO
async packFromStreamToStream() { }
// TODO
async packFromDirPathToStream() { }
// TODO
async packFromDirPathToFs() { }
}
exports.SmartArchive = SmartArchive;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhcmNoaXZlLmNsYXNzZXMuc21hcnRhcmNoaXZlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhcmNoaXZlLmNsYXNzZXMuc21hcnRhcmNoaXZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLGdFQUFrRDtBQUVsRCxNQUFhLFlBQVk7SUFFdkIsZ0JBQWUsQ0FBQztJQUVULDBCQUEwQixDQUFDLFdBQW1CLEVBQUUsU0FBaUI7UUFDdEUsTUFBTSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsV0FBVyxDQUFDLENBQUM7UUFDbkQsUUFBUSxVQUFVLENBQUMsR0FBRyxFQUFFO1NBRXZCO0lBQ0gsQ0FBQztJQUFBLENBQUM7Q0FDSDtBQVZELG9DQVVDIn0=
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhcmNoaXZlLmNsYXNzZXMuc21hcnRhcmNoaXZlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhcmNoaXZlLmNsYXNzZXMuc21hcnRhcmNoaXZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFB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yxDQUFDLDZCQUE2QjtJQUUxQyxDQUFDO0lBRUQsT0FBTztJQUNBLEtBQUssQ0FBQyxrQ0FBa0MsS0FBSSxDQUFDO0lBRXBELE9BQU87SUFDQSxLQUFLLENBQUMsZ0NBQWdDLEtBQUksQ0FBQztJQUVsRCxPQUFPO0lBQ0EsS0FBSyxDQUFDLHNCQUFzQixLQUFJLENBQUM7SUFFeEMsT0FBTztJQUNBLEtBQUssQ0FBQyx1QkFBdUIsS0FBSSxDQUFDO0lBRXpDLE9BQU87SUFDQSxLQUFLLENBQUMsbUJBQW1CLEtBQUksQ0FBQztDQUN0QyJ9

View File

@ -1,13 +1,4 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = __importStar(require("./smartarchive.plugins"));
exports.packageDir = plugins.path.join(__dirname, '../');
exports.nogitDir = plugins.path.join(__dirname, './.nogit');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhcmNoaXZlLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhcmNoaXZlLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLGdFQUFrRDtBQUVyQyxRQUFBLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxTQUFTLEVBQUUsS0FBSyxDQUFDLENBQUM7QUFDakQsUUFBQSxRQUFRLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFFLFVBQVUsQ0FBQyxDQUFDIn0=
import * as plugins from './smartarchive.plugins.js';
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
export const nogitDir = plugins.path.join(packageDir, './.nogit');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhcmNoaXZlLnBhdGhzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhcmNoaXZlLnBhdGhzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxPQUFPLE1BQU0sMkJBQTJCLENBQUM7QUFFckQsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLEVBQUUsS0FBSyxDQUFDLENBQUM7QUFDcEgsTUFBTSxDQUFDLE1BQU0sUUFBUSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBRSxVQUFVLENBQUMsQ0FBQyJ9

View File

@ -1,7 +1,13 @@
import path from 'path';
import * as path from 'path';
export { path };
import * as smartfile from '@pushrocks/smartfile';
import * as smartpath from '@pushrocks/smartpath';
export { smartfile, smartpath };
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartunique from '@pushrocks/smartunique';
import * as smartstream from '@pushrocks/smartstream';
import * as smartrx from '@pushrocks/smartrx';
export { smartfile, smartpath, smartrequest, smartunique, smartstream, smartrx };
import gunzipMaybe from 'gunzip-maybe';
import tar from 'tar';
export { tar };
import tarStream from 'tar-stream';
export { gunzipMaybe, tar, tarStream };

View File

@ -1,24 +1,18 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// node native scope
const path_1 = __importDefault(require("path"));
exports.path = path_1.default;
import * as path from 'path';
export { path };
// @pushrocks scope
const smartfile = __importStar(require("@pushrocks/smartfile"));
exports.smartfile = smartfile;
const smartpath = __importStar(require("@pushrocks/smartpath"));
exports.smartpath = smartpath;
import * as smartfile from '@pushrocks/smartfile';
import * as smartpath from '@pushrocks/smartpath';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartunique from '@pushrocks/smartunique';
import * as smartstream from '@pushrocks/smartstream';
import * as smartrx from '@pushrocks/smartrx';
export { smartfile, smartpath, smartrequest, smartunique, smartstream, smartrx };
// third party scope
const tar_1 = __importDefault(require("tar"));
exports.tar = tar_1.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhcmNoaXZlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFyY2hpdmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFBQSxvQkFBb0I7QUFDcEIsZ0RBQXdCO0FBRWYsZUFGRixjQUFJLENBRUU7QUFFYixtQkFBbUI7QUFDbkIsZ0VBQWtEO0FBR3pDLDhCQUFTO0FBRmxCLGdFQUFrRDtBQUU5Qiw4QkFBUztBQUU3QixvQkFBb0I7QUFDcEIsOENBQXNCO0FBRWIsY0FGRixhQUFHLENBRUUifQ==
import gunzipMaybe from 'gunzip-maybe';
// @ts-ignore
import tar from 'tar';
import tarStream from 'tar-stream';
export { gunzipMaybe, tar, tarStream };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhcmNoaXZlLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFyY2hpdmUucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxvQkFBb0I7QUFDcEIsT0FBTyxLQUFLLElBQUksTUFBTSxNQUFNLENBQUM7QUFFN0IsT0FBTyxFQUFFLElBQUksRUFBRSxDQUFDO0FBRWhCLG1CQUFtQjtBQUNuQixPQUFPLEtBQUssU0FBUyxNQUFNLHNCQUFzQixDQUFDO0FBQ2xELE9BQU8sS0FBSyxTQUFTLE1BQU0sc0JBQXNCLENBQUM7QUFDbEQsT0FBTyxLQUFLLFlBQVksTUFBTSx5QkFBeUIsQ0FBQztBQUN4RCxPQUFPLEtBQUssV0FBVyxNQUFNLHdCQUF3QixDQUFDO0FBQ3RELE9BQU8sS0FBSyxXQUFXLE1BQU0sd0JBQXdCLENBQUM7QUFDdEQsT0FBTyxLQUFLLE9BQU8sTUFBTSxvQkFBb0IsQ0FBQztBQUU5QyxPQUFPLEVBQUUsU0FBUyxFQUFFLFNBQVMsRUFBRSxZQUFZLEVBQUUsV0FBVyxFQUFFLFdBQVcsRUFBRSxPQUFPLEVBQUUsQ0FBQztBQUVqRixvQkFBb0I7QUFDcEIsT0FBTyxXQUFXLE1BQU0sY0FBYyxDQUFDO0FBRXZDLGFBQWE7QUFDYixPQUFPLEdBQUcsTUFBTSxLQUFLLENBQUM7QUFDdEIsT0FBTyxTQUFTLE1BQU0sWUFBWSxDQUFDO0FBRW5DLE9BQU8sRUFBRSxXQUFXLEVBQUUsR0FBRyxFQUFFLFNBQVMsRUFBRSxDQUFDIn0=

18856
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,13 @@
{
"name": "@pushrocks/smartarchive",
"version": "1.0.13",
"version": "3.0.6",
"description": "work with archives",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "tstest test/",
"build": "tsbuild"
"test": "(tstest test/ --web)",
"build": "tsbuild --web --allowimplicitany"
},
"repository": {
"type": "git",
@ -19,23 +20,23 @@
},
"homepage": "https://github.com/pushrocks/smartarchive#readme",
"dependencies": {
"@pushrocks/smartfile": "^8.0.9",
"@pushrocks/smartpath": "^4.0.3",
"@pushrocks/smartrequest": "^1.1.51",
"@pushrocks/smartrx": "^2.0.19",
"@pushrocks/smartfile": "^10.0.1",
"@pushrocks/smartpath": "^5.0.5",
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrequest": "^1.1.56",
"@pushrocks/smartrx": "^2.0.25",
"@pushrocks/smartstream": "^2.0.2",
"@pushrocks/smartunique": "^3.0.3",
"@pushrocks/streamfunction": "^2.0.1",
"@types/gunzip-maybe": "^1.4.0",
"@types/tar": "^4.0.4",
"@types/tar-stream": "^2.2.0",
"@types/tar-stream": "^2.2.2",
"gunzip-maybe": "^1.4.2",
"tar": "^6.1.0",
"tar": "^6.1.11",
"tar-stream": "^2.2.0"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.14",
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tstest": "^1.0.71",
"@pushrocks/tapbundle": "^5.0.3",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},

View File

@ -1,6 +1,7 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as path from 'path';
import * as smartpath from '@pushrocks/smartpath';
import * as smartfile from '@pushrocks/smartfile';
import * as smartrequest from '@pushrocks/smartrequest';
@ -11,11 +12,11 @@ const testPlugins = {
};
const testPaths = {
nogitDir: testPlugins.path.join(__dirname, '../.nogit/'),
remoteDir: testPlugins.path.join(__dirname, '../.nogit/remote'),
nogitDir: testPlugins.path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../.nogit/'),
remoteDir: testPlugins.path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../.nogit/remote'),
};
import * as smartarchive from '../ts/index';
import * as smartarchive from '../ts/index.js';
tap.preTask('should prepare .nogit dir', async () => {
await testPlugins.smartfile.fs.ensureDir(testPaths.remoteDir);
@ -49,7 +50,8 @@ tap.test('should download a package from the registry', async () => {
);
});
tap.test('should extract a package using tarStream', async () => {
tap.test('should extract a package using tarStream', async (tools) => {
const done = tools.defer();
const testSmartarchive = new smartarchive.SmartArchive();
const testTgzBuffer = (
await testPlugins.smartfile.Smartfile.fromFilePath(
@ -59,10 +61,36 @@ tap.test('should extract a package using tarStream', async () => {
const extractionFileObservable = await testSmartarchive.extractArchiveFromBufferToObservable(
testTgzBuffer
);
const subscription = extractionFileObservable.subscribe(file => {
const subscription = extractionFileObservable.subscribe(
(file) => {
console.log(file.path);
},
(err) => {
console.log(err);
},
() => {
done.resolve();
}
);
await done.promise;
});
tap.test('should extract a file from url to replaySubject', async (tools) => {
const done = tools.defer();
const testSmartarchive = new smartarchive.SmartArchive();
const extractionFileObservable = await testSmartarchive.extractArchiveFromUrlToObservable(
'https://verdaccio.lossless.one/@pushrocks%2fwebsetup/-/websetup-2.0.14.tgz'
);
const subscription = extractionFileObservable.subscribe((file) => {
console.log(file.path);
},
(err) => {
console.log(err);
},
() => {
done.resolve();
});
await done.promise;
});
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartarchive',
version: '3.0.6',
description: 'work with archives'
}

View File

@ -1 +1 @@
export * from './smartarchive.classes.smartarchive';
export * from './smartarchive.classes.smartarchive.js';

View File

@ -1,9 +1,7 @@
import * as plugins from './smartarchive.plugins';
import * as paths from './smartarchive.paths';
import { extract } from 'tar';
import * as plugins from './smartarchive.plugins.js';
import * as paths from './smartarchive.paths.js';
export class SmartArchive {
public archiveDirectory: string;
constructor() {}
/**
@ -12,6 +10,7 @@ export class SmartArchive {
public async extractArchiveFromUrlToFs(urlArg: string, targetDir: string) {
const parsedPath = plugins.path.parse(urlArg);
const uniqueFileName = plugins.smartunique.uni() + parsedPath.ext;
plugins.smartfile.fs.ensureDir(paths.nogitDir); // TODO: totally remove caching needs
const downloadPath = plugins.path.join(paths.nogitDir, uniqueFileName);
const downloadedArchive = (await plugins.smartrequest.getBinary(urlArg)).body;
await plugins.smartfile.memory.toFs(downloadedArchive, downloadPath);
@ -22,28 +21,54 @@ export class SmartArchive {
/**
* extracts an archive from a given filePath on disk
* @param filePathArg
* @param targetDir
* @param targetDirArg
*/
public async extractArchiveFromFilePathToFs(filePathArg: string, targetDir: string) {
const parsedPath = plugins.path.parse(filePathArg);
switch (parsedPath.ext) {
case '.tgz':
console.log(`detected a .tgz archive`);
await plugins.tar.extract({
file: filePathArg,
cwd: targetDir,
});
break;
}
public async extractArchiveFromFilePathToFs(filePathArg: string, targetDirArg: string) {
console.log(`extracting ${filePathArg}`);
const done = plugins.smartpromise.defer();
filePathArg = plugins.smartpath.transform.makeAbsolute(filePathArg);
targetDirArg = plugins.smartpath.transform.makeAbsolute(targetDirArg);
const readableStream = plugins.smartfile.fsStream.createReadStream(filePathArg);
const extractPipeStop = plugins.tarStream.extract();
extractPipeStop.on('entry', async (header, stream, next) => {
const targetFilePath = plugins.path.join(targetDirArg, header.name);
const parsedPath = plugins.path.parse(targetFilePath);
await plugins.smartfile.fs.ensureDir(parsedPath.dir);
const writeStream = plugins.smartfile.fsStream.createWriteStream(targetFilePath);
stream.pipe(writeStream);
stream.on('end', () => {
console.log(`extracted ${header.name}`);
next();
})
stream.resume();
});
extractPipeStop.on('finish', () => {
console.log(`Sucessfully extracted ${filePathArg}!`);
done.resolve();
});
// lets run the stream
readableStream
.pipe(plugins.gunzipMaybe())
.pipe(extractPipeStop);
await done.promise;
}
/**
* extracts to Observable
* where the Observable is emitting smartfiles
*/
public async extractArchiveFromBufferToObservable(
bufferArg: Buffer
): Promise<plugins.smartrx.rxjs.ReplaySubject<plugins.smartfile.Smartfile>> {
const intake = new plugins.streamfunction.Intake();
const { intake, replaySubject } = this.extractArchiveWithIntakeAndReplaySubject();
intake.pushData(bufferArg);
intake.signalEnd();
return replaySubject;
}
extractArchiveWithIntakeAndReplaySubject() {
const intake = new plugins.smartstream.StreamIntake<Buffer>();
const replaySubject = new plugins.smartrx.rxjs.ReplaySubject<plugins.smartfile.Smartfile>();
const readableStream = intake.getReadableStream();
const extractPipeStop = plugins.tarStream.extract();
@ -59,8 +84,9 @@ export class SmartArchive {
stream.on('end', () => {
replaySubject.next(
new plugins.smartfile.Smartfile({
base: null, // no working directory for this one
contentBuffer: fileBuffer,
path: header.name,
path: `${header.name}`
})
);
next();
@ -68,14 +94,46 @@ export class SmartArchive {
stream.resume();
});
extractPipeStop.on('finish', () => {
replaySubject.unsubscribe();
replaySubject.complete();
});
// lets run the stream
readableStream
.pipe(plugins.gunzipMaybe())
.pipe(extractPipeStop);
intake.pushData(bufferArg);
intake.signalEnd();
return {
intake,
replaySubject
};
}
/**
* extracts to Observable
*/
public async extractArchiveFromUrlToObservable(
urlArg: string
): Promise<plugins.smartrx.rxjs.ReplaySubject<plugins.smartfile.Smartfile>> {
const response = await plugins.smartrequest.getBinary(urlArg);
const replaySubject = this.extractArchiveFromBufferToObservable(response.body);
return replaySubject;
}
// TODO
public async extractArchiveFromUrlToStream() {
}
// TODO
public async extractArchiveFromFilePathToStream() {}
// TODO
public async extractArchiveFromStreamToStream() {}
// TODO
public async packFromStreamToStream() {}
// TODO
public async packFromDirPathToStream() {}
// TODO
public async packFromDirPathToFs() {}
}

View File

@ -1,5 +1,4 @@
import * as plugins from './smartarchive.plugins';
import * as plugins from './smartarchive.plugins.js';
export const packageDir = plugins.path.join(__dirname, '../');
export const nogitDir = plugins.path.join(__dirname, './.nogit');
plugins.smartfile.fs.ensureDir(nogitDir);
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
export const nogitDir = plugins.path.join(packageDir, './.nogit');

View File

@ -1,20 +1,23 @@
// node native scope
import path from 'path';
import * as path from 'path';
export { path };
// @pushrocks scope
import * as smartfile from '@pushrocks/smartfile';
import * as smartpath from '@pushrocks/smartpath';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartunique from '@pushrocks/smartunique';
import * as streamfunction from '@pushrocks/streamfunction';
import * as smartstream from '@pushrocks/smartstream';
import * as smartrx from '@pushrocks/smartrx';
export { smartfile, smartpath, smartrequest, smartunique, streamfunction, smartrx };
export { smartfile, smartpath, smartpromise, smartrequest, smartunique, smartstream, smartrx };
// third party scope
import gunzipMaybe from 'gunzip-maybe';
// @ts-ignore
import tar from 'tar';
import tarStream from 'tar-stream';

9
tsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
}