//============================================================================ // NFileUtilities::GetFileData : Get a file as data. //---------------------------------------------------------------------------- NData NFileUtilities::GetFileData(const NFile &theFile) { uint64_t theSize, numRead; NFile mutableFile; NData theData; NStatus theErr; // Get the state we need mutableFile = theFile; theSize = mutableFile.GetSize(); NN_ASSERT( ((int64_t) theSize) <= kInt32Max); // Resize the buffer if (!theData.SetSize((NIndex) theSize)) return(theData); // Open the file theErr = mutableFile.Open(); if (theErr != kNoErr) { theData.Clear(); return(theData); } // Read the data theErr = mutableFile.Read(theSize, theData.GetData(), numRead); theData.SetSize((NIndex) numRead); NN_ASSERT_NOERR(theErr); NN_ASSERT(numRead == theSize); NN_ASSERT(((int64_t) numRead) <= kInt32Max); // Clean up mutableFile.Close(); return(theData); }