פיצול קבצי 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 ק״ב ומדפיסה את שם כל חלק עם יצירתו.
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();
אירועים ב‑Aspose.Email עבור C++ הם System::MulticastDelegate מופעים; מטפל מחובר באמצעות connect, הצופה ל‑ std::function עם החתימה של האירוע.
בטל פעולה של פיצול
כדי לעצור פיצול לפני שהארכיון כולו עבר עיבוד - למשל, כאשר נדרשים רק החלקים הראשונים, או כאשר המשתמש מבקש לבטל - קראו ביטול מפן הפנים של MboxFileCreated handler. חלקים שכבר נכתבו נשארים על הדיסק; לא נוצרו חלקים נוספים.
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();