[*] Allow empty file creation via NULL memoryviews
This commit is contained in:
parent
363560e9e9
commit
895ef05887
@ -348,36 +348,40 @@ namespace Aurora::IO::FS
|
||||
|
||||
AUKN_SYM bool WriteNewString(const AuString &path, const AuString &str)
|
||||
{
|
||||
AuIO::IOHandle handle;
|
||||
bool bOk {};
|
||||
AuUInt uLength {};
|
||||
|
||||
static const char bom[3]
|
||||
{
|
||||
'\xEF', '\xBB', '\xBF'
|
||||
};
|
||||
|
||||
auto createRequest = AuIO::IIOHandle::HandleCreate::ReadWrite(path);
|
||||
createRequest.bAlwaysCreateDirTree = true;
|
||||
createRequest.bFailIfNonEmptyFile = true;
|
||||
if (!handle->InitFromPath(createRequest))
|
||||
bool bOk {};
|
||||
|
||||
{
|
||||
return false;
|
||||
AuIO::IOHandle handle;
|
||||
AuUInt uLength {};
|
||||
|
||||
auto createRequest = AuIO::IIOHandle::HandleCreate::ReadWrite(path);
|
||||
createRequest.bAlwaysCreateDirTree = true;
|
||||
createRequest.bFailIfNonEmptyFile = true;
|
||||
if (!handle->InitFromPath(createRequest))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto pStream = FS::OpenBlockingFileStreamFromHandle(AuUnsafeRaiiToShared(handle.AsPointer()));
|
||||
if (!pStream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bOk = pStream->Write(AuMemoryViewStreamRead { bom });
|
||||
bOk &= pStream->Write(AuMemoryViewStreamRead { str, uLength });
|
||||
|
||||
bOk &= uLength == str.length();
|
||||
|
||||
pStream->WriteEoS();
|
||||
pStream->Flush();
|
||||
}
|
||||
|
||||
auto pStream = FS::OpenBlockingFileStreamFromHandle(AuUnsafeRaiiToShared(handle.AsPointer()));
|
||||
if (!pStream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bOk = pStream->Write(AuMemoryViewStreamRead { bom });
|
||||
bOk &= pStream->Write(AuMemoryViewStreamRead { str, uLength });
|
||||
|
||||
bOk &= uLength == str.length();
|
||||
|
||||
pStream->WriteEoS();
|
||||
pStream->Flush();
|
||||
RuntimeWaitForSecondaryTick();
|
||||
|
||||
return bOk;
|
||||
}
|
||||
@ -385,29 +389,34 @@ namespace Aurora::IO::FS
|
||||
AUKN_SYM bool WriteNewFile(const AuString &path, const Memory::MemoryViewRead &blob)
|
||||
{
|
||||
bool bOk {};
|
||||
AuUInt uLength {};
|
||||
AuIO::IOHandle handle;
|
||||
|
||||
auto createRequest = AuIO::IIOHandle::HandleCreate::ReadWrite(path);
|
||||
createRequest.bAlwaysCreateDirTree = true;
|
||||
createRequest.bFailIfNonEmptyFile = true;
|
||||
|
||||
if (!handle->InitFromPath(createRequest))
|
||||
|
||||
{
|
||||
return false;
|
||||
AuUInt uLength {};
|
||||
AuIO::IOHandle handle;
|
||||
|
||||
auto createRequest = AuIO::IIOHandle::HandleCreate::ReadWrite(path);
|
||||
createRequest.bAlwaysCreateDirTree = true;
|
||||
createRequest.bFailIfNonEmptyFile = true;
|
||||
|
||||
if (!handle->InitFromPath(createRequest))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto pStream = FS::OpenBlockingFileStreamFromHandle(AuUnsafeRaiiToShared(handle.AsPointer()));
|
||||
if (!pStream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bOk = pStream->Write(AuMemoryViewStreamRead { blob, uLength });
|
||||
pStream->WriteEoS();
|
||||
pStream->Flush();
|
||||
|
||||
bOk &= uLength == blob.length;
|
||||
}
|
||||
|
||||
auto pStream = FS::OpenBlockingFileStreamFromHandle(AuUnsafeRaiiToShared(handle.AsPointer()));
|
||||
if (!pStream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bOk = pStream->Write(AuMemoryViewStreamRead { blob, uLength });
|
||||
pStream->WriteEoS();
|
||||
pStream->Flush();
|
||||
|
||||
bOk &= uLength == blob.length;
|
||||
RuntimeWaitForSecondaryTick();
|
||||
|
||||
return bOk;
|
||||
}
|
||||
@ -432,11 +441,18 @@ namespace Aurora::IO::FS
|
||||
return false;
|
||||
}
|
||||
|
||||
bOk = pStream->Write(AuMemoryViewStreamRead { blob, uLength });
|
||||
pStream->WriteEoS();
|
||||
pStream->Flush();
|
||||
if (blob.length)
|
||||
{
|
||||
bOk = pStream->Write(AuMemoryViewStreamRead { blob, uLength });
|
||||
bOk &= uLength == blob.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
bOk = true;
|
||||
}
|
||||
|
||||
bOk &= uLength == blob.length;
|
||||
pStream->WriteEoS();
|
||||
pStream->SetFlushOnClose(true);
|
||||
return bOk;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user