Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
abe1299203 | |||
99ce99795a | |||
f6a54ead5d | |||
cb48cfa948 | |||
36a5c2480f | |||
70a08fd92b | |||
02a0646a49 | |||
17eda1e56a | |||
ea6c514a40 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartarchive",
|
"name": "@pushrocks/smartarchive",
|
||||||
"version": "1.0.14",
|
"version": "2.0.4",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartarchive",
|
"name": "@pushrocks/smartarchive",
|
||||||
"version": "1.0.14",
|
"version": "2.0.4",
|
||||||
"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",
|
||||||
|
33
test/test.ts
33
test/test.ts
@ -49,7 +49,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 +60,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(
|
||||||
|
(file) => {
|
||||||
console.log(file.path);
|
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();
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,3 @@ import * as plugins from './smartarchive.plugins';
|
|||||||
|
|
||||||
export const packageDir = plugins.path.join(__dirname, '../');
|
export const packageDir = plugins.path.join(__dirname, '../');
|
||||||
export const nogitDir = plugins.path.join(__dirname, './.nogit');
|
export const nogitDir = plugins.path.join(__dirname, './.nogit');
|
||||||
plugins.smartfile.fs.ensureDir(nogitDir);
|
|
||||||
|
Reference in New Issue
Block a user