MBOX फ़ाइलों को विभाजित करना
बहुत बड़े MBOX फ़ाइलों की कॉपी, बैकअप और खोलना धीमा होता है। SplitInto की विधि MboxStorageReader अभिलेख के संदेशों को लगभग आपके द्वारा चुने आकार के भाग फ़ाइलों में लिखता है। संदेश कभी मध्य में नहीं काटे जाते: जब भाग का आकार सीमा तक पहुंचता है तो वह बंद हो जाता है, इसलिए बड़े संदेश जोड़ने पर भाग थोड़ा बड़ा हो सकता है.
नीचे के नमूने निम्न हेडर और नेमस्पेस का उपयोग करते हैं:
#include <Storage/Mbox/MboxrdStorageReader.h>
#include <Storage/Mbox/MboxLoadOptions.h>
#include <Storage/NewStorageEventArgs.h>
#include <system/io/directory.h>
#include <system/convert.h>
using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Storage;
using namespace Aspose::Email::Storage::Mbox;
अभिलेख को भागों में विभाजित करें
SplitInto बाइट्स में चंक साइज, आउटपुट डायरेक्टरी और वैकल्पिक रूप से भाग फ़ाइल नामों के लिए प्रीफ़िक्स लेता है। हर बार नया भाग खुलने पर रीडर यह इवेंट उठाता है MboxFileCreated इवेंट; इससे जुड़ा एक हैंडलर एक NewStorageEventArgs ऑब्जेक्ट जिसका FileName फ़ाइल का प्रॉपर्टी नाम. उदाहरण एक अभिलेख को लगभग 50 KB के भागों में विभाजित करता है और प्रत्येक भाग का नाम बनते ही प्रिंट करता है.
SharedPtr<MboxLoadOptions> options = MakeObject<MboxLoadOptions>();
options->set_LeaveOpen(false);
SharedPtr<MboxrdStorageReader> reader = MakeObject<MboxrdStorageReader>(u"mailbox.mbox", options);
IO::Directory::CreateDirectory_(u"Chunks");
// Get notified every time a new part file is created
reader->MboxFileCreated.connect(std::function<void(SharedPtr<Object>, SharedPtr<NewStorageEventArgs>)>(
[](SharedPtr<Object> sender, SharedPtr<NewStorageEventArgs> e)
{
Console::WriteLine(u"Created: " + e->get_FileName());
}));
// Split the archive into parts of roughly 50 KB each, using the "part_" file name prefix
reader->SplitInto(50 * 1024, u"Chunks", u"part_");
reader->Dispose();
C++ के लिए Aspose.Email में इवेंट्स हैं System::MulticastDelegate इंस्टैंस की अपेक्षा करता है; एक हैंडलर इस प्रकार जुड़ता है connect, जो एक std::function इवेंट के सिग्नेचर के साथ.
विभाजन ऑपरेशन रद्द करें
पूरे अभिलेख को प्रोसेस करने से पहले विभाजन रोकने के लिए - उदाहरण के लिए, जब केवल पहले कुछ भागों की आवश्यकता हो, या उपयोगकर्ता रद्द करने को कहे - कॉल करें रद्द करें के भीतर से MboxFileCreated हैंडलर. पहले से लिखे गए भाग डिस्क पर बने रहते हैं; आगे कोई भाग नहीं बनते.
int32_t partCount = 0;
SharedPtr<MboxLoadOptions> options = MakeObject<MboxLoadOptions>();
options->set_LeaveOpen(false);
SharedPtr<MboxrdStorageReader> reader = MakeObject<MboxrdStorageReader>(u"mailbox.mbox", options);
IO::Directory::CreateDirectory_(u"Chunks-Cancel");
// Stop after the second part has been created
reader->MboxFileCreated.connect(std::function<void(SharedPtr<Object>, SharedPtr<NewStorageEventArgs>)>(
[&partCount, reader](SharedPtr<Object> sender, SharedPtr<NewStorageEventArgs> e)
{
partCount++;
if (partCount >= 2)
{
reader->Cancel();
}
}));
reader->SplitInto(20 * 1024, u"Chunks-Cancel");
Console::WriteLine(u"Parts created: " + Convert::ToString(partCount));
reader->Dispose();