2
0
Fork 0
OB-Xd/Modules/gin/utilities/fileutilities.cpp

44 lines
1.1 KiB
C++
Raw Normal View History

2020-05-21 07:14:57 +00:00
/*==============================================================================
Copyright 2019 by Roland Rabien
For more information visit www.rabiensoftware.com
==============================================================================*/
bool overwriteWithText (const juce::File& f, const juce::String& text, bool asUnicode,
bool writeUnicodeHeaderBytes,
const char* lineEndings)
{
FileOutputStream out (f);
if (out.failedToOpen())
return false;
out.setPosition (0);
bool ok = out.writeText (text, asUnicode, writeUnicodeHeaderBytes, lineEndings);
out.truncate();
return ok;
}
bool overwriteWithData (const juce::File& f, const juce::MemoryBlock& data)
{
return overwriteWithData (f, data.getData(), data.getSize());
}
bool overwriteWithData (const juce::File& f, const void* data, size_t size)
{
FileOutputStream out (f);
if (out.failedToOpen())
return false;
out.setPosition (0);
bool ok = true;
if (size > 0)
ok = out.write (data, size);
out.truncate();
return ok;
}