MBOX 파일 분할
Contents
[
Hide
]
매우 큰 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 속성은 파일 이름을 지정합니다. 예제는 아카이브를 약 50KB 크기의 파트로 나누고 생성될 때마다 각 파트 이름을 출력합니다.
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 이벤트 서명과 함께.
분할 작업 취소
전체 아카이브가 처리되기 전에 분할을 중단하려면(예: 처음 몇 개 파트만 필요하거나 사용자가 중단을 요청할 때) 다음을 호출하십시오 Cancel 내부에서 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();