C# और .NET में Archive Files Extract करें

.NET applications में ZIP और दूसरे archive formats को programmatically unpack करें।

.NET में Archive File Extraction

Aspose.ZIP for .NET एक managed library है, जिससे C# applications में archives खोलकर उनका content निकाला जा सकता है। इसकी APIs archive entries पढ़ने, पूरा archive या चुनी हुई entries extract करने, directory structure बनाए रखने और output को folder या stream में लिखने देती हैं। Processing application के भीतर रहती है, इसलिए server-side workflows को desktop software या command-line utilities पर निर्भर नहीं रहना पड़ता।

इसका उपयोग document ingestion, backup restore, deployment packages, upload processing और automated data exchange जैसे scenarios में किया जा सकता है। यही API ASP.NET services, background workers, desktop applications, cloud jobs और CI/CD tooling में चल सकती है। कौन-से formats और entries स्वीकार किए जाएं तथा output कहां लिखा जाए, इसका नियंत्रण application के पास रहता है।

हर format का workflow एक जैसा नहीं होता। ZIP, 7Z, RAR, TAR और CAB की container structure, compression methods और API classes अलग हैं। यह overview साझा extraction flow समझाता है; इसके बाद format-specific guides सही class, options और limitations बताते हैं।

Archive File Extractor क्या होता है?

Archive file extractor उस container को खोलता है जिसमें एक या अधिक files होती हैं और stored content को उसकी उपयोग योग्य अवस्था में वापस लिखता है। सामान्यतः यह archive metadata पढ़ता है, entries और directories पहचानता है, data decompress करता है और result को स्वीकृत location पर लिखता है। Encrypted archive के लिए उस format द्वारा समर्थित settings और सही credentials भी आवश्यक होते हैं।

Extract, unpack और decompress शब्द अक्सर एक ही अर्थ में उपयोग किए जाते हैं। Developers जब files unzip करने की बात करते हैं, तो उनका मतलब ZIP container से content निकालना होता है। Archive extraction व्यापक operation है और इसमें 7Z, RAR, TAR, CAB, CPIO तथा XZ जैसे formats भी शामिल हैं।

Production में extraction केवल एक method call नहीं है। Application को entry names inspect करने, कुछ items चुनने, folders बनाए रखने, streams स्वीकार करने, passwords संभालने, failures report करने और permanent storage में लिखने से पहले limits लागू करने की आवश्यकता हो सकती है।

Archive Extraction कैसे काम करता है

एक सामान्य C# workflow में ये सात चरण होते हैं:

  1. Local path, upload, stream या storage service से archive प्राप्त करें।
  2. जांचें कि application उस archive format को स्वीकार करती है।
  3. उस format के लिए बनी API class से container खोलें।
  4. Filtering या selective extraction चाहिए तो archive entries inspect करें।
  5. कोई file लिखने से पहले entry paths और resource limits validate करें।
  6. स्वीकृत entries को isolated destination में extract करें।
  7. Output को अगले application stage तक भेजें और temporary data हटा दें।

Input type के अनुसार opening class बदलती है, क्योंकि ZIP, 7Z, RAR, TAR और CAB का internal model समान नहीं है। फिर भी service application-level पर एक workflow दे सकती है और हर container को संबंधित Aspose.ZIP API तक route कर सकती है।

Extraction के लिए उपलब्ध Archive Formats

Library लोकप्रिय archive और compression formats के साथ काम करती है, जिनमें ZIP, 7Z, RAR, TAR, GZIP, BZIP2, XZ, LZIP, Z, CPIO, CAB और WIM शामिल हैं। उपलब्ध operations format के अनुसार बदलते हैं: कुछ formats में कई entries होती हैं, जबकि कुछ केवल एक compressed stream या अतिरिक्त compression layer में wrapped TAR container को दर्शाते हैं।

केवल filename extension पर निर्भर न रहें; वास्तविक container से मेल खाने वाला handler चुनें। किसी format को automated pipeline में जोड़ने से पहले जांचें कि आवश्यक operation, encryption method और stream behavior समर्थित हैं।

सामान्य File Extraction Workflows

पूरा archive unpack करें। जब सभी entries चाहिए और input validation पास कर चुका हो, तब full extraction उपयोग करें। आवश्यकता होने पर मूल directory hierarchy बनाए रखें और हर job को unique destination दें, ताकि concurrent requests एक-दूसरे का output overwrite या mix न करें।

केवल चुनी हुई entries पढ़ें। Data लिखने से पहले Archive.Entries inspect करें और application rules लागू करें। यह तब उपयोगी है जब package में कई assets हों लेकिन workflow को केवल document, manifest, configuration file या ज्ञात folder चाहिए। इससे अनावश्यक disk writes भी बचती हैं।

Stream process करें। Stream-based input ASP.NET uploads, object storage, databases और message-driven systems के लिए उपयुक्त है। Stream का owner और lifetime स्पष्ट रखें तथा बिना size limit वाले archive को पूरा memory में buffer न करें।

Protected content खोलें। संबंधित format की decryption settings के माध्यम से credentials दें। Passwords protected configuration या secret store से आने चाहिए और logs में कभी नहीं लिखे जाने चाहिए। Credentials न मिलने या गलत होने पर नियंत्रित application error लौटाएं।

बड़े inputs को bounded jobs की तरह संभालें। Compressed size, extracted size, entry count, processing time और temporary storage usage की limits तय करें। केवल extension देखकर input को trusted न मानें।

C# Project में Aspose.ZIP जोड़ें

Windows, Linux या macOS पर supported .NET environment target करने वाले C# project में Aspose.ZIP NuGet package install करें। इसके बाद आवश्यक namespace reference करें और input container से मेल खाने वाली class चुनें। Process को source पर read access, destination पर write access और configured expansion limit के लिए पर्याप्त temporary storage भी चाहिए।

यह Package Manager Console command उपयोग करें:

Package Manager Console

PM> Install-Package Aspose.Zip

C# उदाहरण: ZIP File Unpack करें

ZIP साझा workflow का संक्षिप्त उदाहरण देता है। Code input खोलकर उसका content destination directory में लिखता है। External files के साथ यह pattern उपयोग करने से पहले container, output paths और resource limits validate करें।

ZIP Content को Directory में Extract करें

using Aspose.Zip;
using System.IO;

string archivePath = Path.GetFullPath("input.zip");
string outputDirectory = Path.GetFullPath("extracted");

Directory.CreateDirectory(outputDirectory);

using (var archive = new Archive(archivePath))
{
    archive.ExtractToDirectory(outputDirectory);
}

Production में Archives को सुरक्षित रूप से Extract करें

Users या external systems से मिले archives को untrusted input मानें। अपेक्षित extension इस बात का प्रमाण नहीं है कि container valid या सुरक्षित है। जांचें कि चुना गया handler data parse कर सकता है और malformed या unsupported input को reject करें।

Entry लिखने से पहले उसका output path स्वीकृत destination के सापेक्ष resolve करें। Absolute paths, parent-directory traversal और approved directory से बाहर जाने वाले किसी भी result को reject करें। इससे archive में रखा filename filesystem के किसी दूसरे स्थान पर write redirect नहीं कर पाएगा।

Compressed size, कुल extracted size, प्रत्येक entry का size, entry count, nesting depth, execution time और concurrency की limits तय करें। ये controls decompression bombs और storage exhaustion का risk घटाते हैं। हर job के लिए restricted permissions वाला अलग temporary folder उपयोग करें, केवल validated output को आगे बढ़ाएं और success तथा failure दोनों स्थितियों में cleanup करें।

Logs में operation identifiers और status information रखें, passwords, private filenames या extracted content नहीं। यदि output को बाद में parse, preview या scan किया जाएगा, तो हर downstream component को अलग trust boundary मानें।

Browser में Extraction आजमाएं

Free browser-based extraction app से बिना software install किए sample input जांचा जा सकता है। C# workflow implement करने से पहले अपेक्षित output देखने के लिए यह उपयोगी है।

Online tool interactive काम के लिए है। .NET library repeatable services, background processing, storage pipelines और enterprise applications के लिए बनी है, जहां validation तथा output handling application के नियंत्रण में रहनी चाहिए।

हर Archive Type के लिए Extraction Guidance

Implementation details container के अनुसार बदलती हैं। Format-specific guide में यह जानकारी होनी चाहिए:

  • archive खोलने के लिए सही Aspose.ZIP class;
  • full और selective extraction examples;
  • password तथा encryption behavior;
  • उपलब्ध होने पर stream-based processing;
  • format-specific restrictions और production considerations;
  • संबंधित API reference और documentation।

इस overview से implementation पर जाते समय वास्तविक input type का guide उपयोग करें। इससे ZIP की assumptions को अलग behavior वाले 7Z, RAR, TAR, CAB या stream-compression formats पर लागू करने की गलती नहीं होगी।

File Format के अनुसार Archive Extraction Guides

ZIP archives में सामान्यतः रखी जाने वाली files और assets के लिए C# extraction pages देखें।

Archive Extraction Resources

Archive Extraction FAQ

1. C# में archive files कैसे extract करें?

Aspose.ZIP install करें, input को उसके format से मेल खाने वाली class से खोलें और पूरा container या चुनी हुई entries स्वीकृत directory अथवा stream में extract करें।

2. ZIP archive से files कैसे extract करें?

ZIP input के लिए Archive instance बनाएं और पूरा content unpack करने के लिए ExtractToDirectory call करें। केवल selected items inspect या save करने हों तो Archive.Entries enumerate करें।

3. Archive extract करना और files unzip करना क्या एक ही है?

Unzip विशेष रूप से ZIP files के लिए उपयोग होता है। Extraction व्यापक operation है और इसमें 7Z, RAR, TAR, CAB, CPIO तथा WIM भी शामिल हैं।

4. क्या .NET applications password-protected archives खोल सकती हैं?

Valid credentials और सही decryption settings मिलने पर Aspose.ZIP लागू formats के लिए password-based access support करता है। Exact behavior container type पर निर्भर करता है।

5. Uploaded archives को सुरक्षित रूप से कैसे extract करें?

Isolated temporary storage उपयोग करें, हर output path validate करें, accepted formats सीमित रखें, compressed तथा extracted size limits लागू करें, processing timeout तय करें और operation के बाद temporary data हटा दें।