Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
69cf63c80a | |||
14e823fbfd | |||
abe1299203 | |||
99ce99795a | |||
f6a54ead5d | |||
cb48cfa948 | |||
36a5c2480f | |||
70a08fd92b | |||
02a0646a49 | |||
17eda1e56a | |||
ea6c514a40 |
23483
package-lock.json
generated
23483
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
25
package.json
25
package.json
@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartarchive",
|
"name": "@pushrocks/smartarchive",
|
||||||
"version": "1.0.14",
|
"version": "3.0.0",
|
||||||
"description": "work with archives",
|
"description": "work with archives",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "tsbuild --web"
|
"build": "tsbuild --web"
|
||||||
@ -19,23 +20,23 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/pushrocks/smartarchive#readme",
|
"homepage": "https://github.com/pushrocks/smartarchive#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^8.0.9",
|
"@pushrocks/smartfile": "^9.0.6",
|
||||||
"@pushrocks/smartpath": "^4.0.3",
|
"@pushrocks/smartpath": "^5.0.5",
|
||||||
"@pushrocks/smartrequest": "^1.1.51",
|
"@pushrocks/smartrequest": "^1.1.56",
|
||||||
"@pushrocks/smartrx": "^2.0.19",
|
"@pushrocks/smartrx": "^2.0.25",
|
||||||
"@pushrocks/smartunique": "^3.0.3",
|
"@pushrocks/smartunique": "^3.0.3",
|
||||||
"@pushrocks/streamfunction": "^2.0.1",
|
"@pushrocks/streamfunction": "^4.0.1",
|
||||||
"@types/gunzip-maybe": "^1.4.0",
|
"@types/gunzip-maybe": "^1.4.0",
|
||||||
"@types/tar": "^4.0.4",
|
"@types/tar": "^6.1.1",
|
||||||
"@types/tar-stream": "^2.2.0",
|
"@types/tar-stream": "^2.2.2",
|
||||||
"gunzip-maybe": "^1.4.2",
|
"gunzip-maybe": "^1.4.2",
|
||||||
"tar": "^6.1.0",
|
"tar": "^6.1.11",
|
||||||
"tar-stream": "^2.2.0"
|
"tar-stream": "^2.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.61",
|
||||||
"@gitzone/tstest": "^1.0.52",
|
"@gitzone/tstest": "^1.0.70",
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
|
40
test/test.ts
40
test/test.ts
@ -1,6 +1,7 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as smartpath from '@pushrocks/smartpath';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
|
||||||
@ -11,11 +12,11 @@ const testPlugins = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const testPaths = {
|
const testPaths = {
|
||||||
nogitDir: testPlugins.path.join(__dirname, '../.nogit/'),
|
nogitDir: testPlugins.path.join(smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../.nogit/'),
|
||||||
remoteDir: testPlugins.path.join(__dirname, '../.nogit/remote'),
|
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 () => {
|
tap.preTask('should prepare .nogit dir', async () => {
|
||||||
await testPlugins.smartfile.fs.ensureDir(testPaths.remoteDir);
|
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 testSmartarchive = new smartarchive.SmartArchive();
|
||||||
const testTgzBuffer = (
|
const testTgzBuffer = (
|
||||||
await testPlugins.smartfile.Smartfile.fromFilePath(
|
await testPlugins.smartfile.Smartfile.fromFilePath(
|
||||||
@ -59,10 +61,36 @@ tap.test('should extract a package using tarStream', async () => {
|
|||||||
const extractionFileObservable = await testSmartarchive.extractArchiveFromBufferToObservable(
|
const extractionFileObservable = await testSmartarchive.extractArchiveFromBufferToObservable(
|
||||||
testTgzBuffer
|
testTgzBuffer
|
||||||
);
|
);
|
||||||
const subscription = extractionFileObservable.subscribe(file => {
|
const subscription = extractionFileObservable.subscribe(
|
||||||
console.log(file.path);
|
(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();
|
tap.start();
|
||||||
|
@ -1 +1 @@
|
|||||||
export * from './smartarchive.classes.smartarchive';
|
export * from './smartarchive.classes.smartarchive.js';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as plugins from './smartarchive.plugins';
|
import * as plugins from './smartarchive.plugins.js';
|
||||||
import * as paths from './smartarchive.paths';
|
import * as paths from './smartarchive.paths.js';
|
||||||
import { extract } from 'tar';
|
import { extract } from 'tar';
|
||||||
|
|
||||||
export class SmartArchive {
|
export class SmartArchive {
|
||||||
@ -12,6 +12,7 @@ export class SmartArchive {
|
|||||||
public async extractArchiveFromUrlToFs(urlArg: string, targetDir: string) {
|
public async extractArchiveFromUrlToFs(urlArg: string, targetDir: string) {
|
||||||
const parsedPath = plugins.path.parse(urlArg);
|
const parsedPath = plugins.path.parse(urlArg);
|
||||||
const uniqueFileName = plugins.smartunique.uni() + parsedPath.ext;
|
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 downloadPath = plugins.path.join(paths.nogitDir, uniqueFileName);
|
||||||
const downloadedArchive = (await plugins.smartrequest.getBinary(urlArg)).body;
|
const downloadedArchive = (await plugins.smartrequest.getBinary(urlArg)).body;
|
||||||
await plugins.smartfile.memory.toFs(downloadedArchive, downloadPath);
|
await plugins.smartfile.memory.toFs(downloadedArchive, downloadPath);
|
||||||
@ -68,7 +69,7 @@ export class SmartArchive {
|
|||||||
stream.resume();
|
stream.resume();
|
||||||
});
|
});
|
||||||
extractPipeStop.on('finish', () => {
|
extractPipeStop.on('finish', () => {
|
||||||
replaySubject.unsubscribe();
|
replaySubject.complete();
|
||||||
});
|
});
|
||||||
// lets run the stream
|
// lets run the stream
|
||||||
readableStream
|
readableStream
|
||||||
@ -78,4 +79,15 @@ export class SmartArchive {
|
|||||||
intake.signalEnd();
|
intake.signalEnd();
|
||||||
return replaySubject;
|
return 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
|
||||||
export const nogitDir = plugins.path.join(__dirname, './.nogit');
|
export const nogitDir = plugins.path.join(packageDir, './.nogit');
|
||||||
plugins.smartfile.fs.ensureDir(nogitDir);
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// node native scope
|
// node native scope
|
||||||
import path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export { path };
|
export { path };
|
||||||
|
|
||||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext"
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user