Compare commits
	
		
			18 Commits
		
	
	
		
			v4.0.23
			...
			538eced73b
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 538eced73b | |||
| fe8a5713f0 | |||
| 37e8a1d0f7 | |||
| 5143cd098d | |||
| 4d5ea812af | |||
| 500ef01ded | |||
| 3196a02835 | |||
| de1c46ed0a | |||
| b4c7b065fa | |||
| 93da11a951 | |||
| ecd7f6d419 | |||
| a3ecfe4d99 | |||
| f99f6d96c5 | |||
| b4be70f43a | |||
| 785e26e72d | |||
| e1891a6aa3 | |||
| f257c0c5a4 | |||
| 725546e409 | 
							
								
								
									
										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
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								package.json
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "@push.rocks/smartarchive", | ||||
|   "version": "4.0.23", | ||||
|   "version": "4.0.32", | ||||
|   "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,13 +22,13 @@ | ||||
|   "homepage": "https://code.foss.global/push.rocks/smartarchive", | ||||
|   "dependencies": { | ||||
|     "@push.rocks/smartdelay": "^3.0.5", | ||||
|     "@push.rocks/smartfile": "^11.0.4", | ||||
|     "@push.rocks/smartpath": "^5.0.11", | ||||
|     "@push.rocks/smartfile": "^11.0.20", | ||||
|     "@push.rocks/smartpath": "^5.0.18", | ||||
|     "@push.rocks/smartpromise": "^4.0.3", | ||||
|     "@push.rocks/smartrequest": "^2.0.21", | ||||
|     "@push.rocks/smartrequest": "^2.0.22", | ||||
|     "@push.rocks/smartrx": "^3.0.7", | ||||
|     "@push.rocks/smartstream": "^3.0.34", | ||||
|     "@push.rocks/smartunique": "^3.0.8", | ||||
|     "@push.rocks/smartstream": "^3.0.44", | ||||
|     "@push.rocks/smartunique": "^3.0.9", | ||||
|     "@push.rocks/smarturl": "^3.0.7", | ||||
|     "@types/tar-stream": "^3.1.3", | ||||
|     "fflate": "^0.8.2", | ||||
| @@ -37,10 +37,10 @@ | ||||
|     "through": "^2.3.8" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@git.zone/tsbuild": "^2.1.72", | ||||
|     "@git.zone/tsbuild": "^2.1.80", | ||||
|     "@git.zone/tsrun": "^1.2.44", | ||||
|     "@git.zone/tstest": "^1.0.88", | ||||
|     "@push.rocks/tapbundle": "^5.0.17" | ||||
|     "@git.zone/tstest": "^1.0.90", | ||||
|     "@push.rocks/tapbundle": "^5.0.23" | ||||
|   }, | ||||
|   "private": false, | ||||
|   "files": [ | ||||
|   | ||||
							
								
								
									
										7646
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										7646
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -3,6 +3,6 @@ | ||||
|  */ | ||||
| export const commitinfo = { | ||||
|   name: '@push.rocks/smartarchive', | ||||
|   version: '4.0.23', | ||||
|   version: '4.0.32', | ||||
|   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; | ||||
| @@ -122,6 +122,11 @@ export class SmartArchive { | ||||
|           if (analyzedResultChunk.fileType?.mime === 'application/x-tar') { | ||||
|             const tarStream = analyzedResultChunk.decompressionStream as plugins.tarStream.Extract; | ||||
|             tarStream.on('entry', async (header, stream, next) => { | ||||
|               if (header.type === 'directory') { | ||||
|                 console.log(`tar stream directory: ${header.name} ... skipping!`); | ||||
|                 next(); | ||||
|                 return; | ||||
|               } | ||||
|               console.log(`tar stream file: ${header.name}`); | ||||
|               const streamfile = plugins.smartfile.StreamFile.fromStream(stream, header.name); | ||||
|               streamFileIntake.push(streamfile); | ||||
|   | ||||
| @@ -2,28 +2,116 @@ import type { SmartArchive } from './classes.smartarchive.js'; | ||||
| import * as plugins from './plugins.js'; | ||||
|  | ||||
| export class TarTools { | ||||
|   smartArchiveRef: SmartArchive; | ||||
|   // INSTANCE | ||||
|   constructor() {} | ||||
|  | ||||
|   constructor(smartArchiveRefArg: SmartArchive) { | ||||
|     this.smartArchiveRef = smartArchiveRefArg; | ||||
|   } | ||||
|    | ||||
|   // packing | ||||
|   public addFileToPack(pack: plugins.tarStream.Pack, fileName: string, content: string | Buffer) { | ||||
|     return new Promise<void>((resolve, reject) => { | ||||
|       const entry = pack.entry({ name: fileName, size: content.length }, (err: Error) => { | ||||
|         if (err) { | ||||
|           reject(err); | ||||
|         } else { | ||||
|           resolve(); | ||||
|         } | ||||
|       }); | ||||
|   public async addFileToPack( | ||||
|     pack: plugins.tarStream.Pack, | ||||
|     optionsArg: { | ||||
|       fileName?: string; | ||||
|       content?: | ||||
|         | string | ||||
|         | Buffer | ||||
|         | plugins.smartstream.stream.Readable | ||||
|         | plugins.smartfile.SmartFile | ||||
|         | plugins.smartfile.StreamFile; | ||||
|       byteLength?: number; | ||||
|       filePath?: string; | ||||
|     } | ||||
|   ): 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; | ||||
|  | ||||
|       entry.write(content); | ||||
|       entry.end(); | ||||
|       /** | ||||
|        * contentByteLength is used to set the size of the entry in the tar file | ||||
|        */ | ||||
|       let contentByteLength: number; | ||||
|       if (optionsArg.byteLength) { | ||||
|         contentByteLength = optionsArg.byteLength; | ||||
|       } else if (typeof optionsArg.content === 'string') { | ||||
|         contentByteLength = Buffer.byteLength(optionsArg.content, 'utf8'); | ||||
|       } else if (Buffer.isBuffer(optionsArg.content)) { | ||||
|         contentByteLength = optionsArg.content.length; | ||||
|       } else if (optionsArg.content instanceof plugins.smartfile.SmartFile) { | ||||
|         contentByteLength = await optionsArg.content.getSize(); // assuming SmartFile has getSize method | ||||
|       } else if (optionsArg.content instanceof plugins.smartfile.StreamFile) { | ||||
|         contentByteLength = await optionsArg.content.getSize(); // assuming StreamFile has getSize method | ||||
|       } else if (optionsArg.content instanceof plugins.smartstream.stream.Readable) { | ||||
|         console.warn( | ||||
|           '@push.rocks/smartarchive: When streaming, it is recommended to provide byteLength, if known.' | ||||
|         ); | ||||
|       } else if (optionsArg.filePath) { | ||||
|         const fileStat = await plugins.smartfile.fs.stat(optionsArg.filePath); | ||||
|         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, | ||||
|           ...(contentByteLength | ||||
|             ? { | ||||
|                 size: contentByteLength, | ||||
|               } | ||||
|             : null), | ||||
|         }, | ||||
|         (err: Error) => { | ||||
|           if (err) { | ||||
|             reject(err); | ||||
|           } else { | ||||
|             resolve(); | ||||
|           } | ||||
|         } | ||||
|       ); | ||||
|  | ||||
|       content.pipe(entry); | ||||
|       entry.on('end', () => { | ||||
|         resolve(); | ||||
|       }); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * packs a directory from disk into a tar stream | ||||
|    * @param directoryPath | ||||
|    */ | ||||
|   public async packDirectory(directoryPath: string) { | ||||
|     const fileTree = await plugins.smartfile.fs.listFileTree(directoryPath, '**/*'); | ||||
|     const pack = await this.getPackStream(); | ||||
|     for (const filePath of fileTree) { | ||||
|       const absolutePath = plugins.path.join(directoryPath, filePath); | ||||
|       const fileStat = await plugins.smartfile.fs.stat(absolutePath); | ||||
|       await this.addFileToPack(pack, { | ||||
|         byteLength: fileStat.size, | ||||
|         filePath: filePath, | ||||
|         fileName: filePath, | ||||
|         content: plugins.smartfile.fsStream.createReadStream(absolutePath), | ||||
|       }); | ||||
|     } | ||||
|     return pack; | ||||
|   } | ||||
|  | ||||
|   public async getPackStream() { | ||||
|     const pack = plugins.tarStream.pack(); | ||||
|     return pack; | ||||
|   | ||||
| @@ -5,7 +5,7 @@ class DecompressZipTransform extends plugins.smartstream.SmartDuplex<ArrayBuffer | ||||
|   private streamtools: plugins.smartstream.IStreamTools; | ||||
|   private unzipper = new plugins.fflate.Unzip(async (fileArg) => { | ||||
|     let resultBuffer: Buffer; | ||||
|     fileArg.ondata = async (dataArg, dat, final) => { | ||||
|     fileArg.ondata = async (flateError, dat, final) => { | ||||
|       resultBuffer? resultBuffer = Buffer.concat([resultBuffer, Buffer.from(dat)]) | ||||
|         : resultBuffer = Buffer.from(dat); | ||||
|       if (final) { | ||||
| @@ -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