String FileReaderLoader::stringResult() { ASSERT(m_readType != ReadAsArrayBuffer && m_readType != ReadAsBlob && m_readType != ReadByClient); // If the loading is not started or an error occurs, return an empty result. if (!m_rawData || m_errorCode) return m_stringResult; // If already converted from the raw data, return the result now. if (m_isRawDataConverted) return m_stringResult; switch (m_readType) { case ReadAsArrayBuffer: // No conversion is needed. break; case ReadAsBinaryString: m_stringResult = m_rawData->toString(); m_isRawDataConverted = true; break; case ReadAsText: convertToText(); break; case ReadAsDataURL: // Partial data is not supported when reading as data URL. if (m_finishedLoading) convertToDataURL(); break; default: ASSERT_NOT_REACHED(); } return m_stringResult; }
String FileReaderLoader::stringResult() { ASSERT(m_readType != ReadAsArrayBuffer && m_readType != ReadAsBlob); // If the loading is not started or an error occurs, return an empty result. if (!m_rawData || m_errorCode) return m_stringResult; // If already converted from the raw data, return the result now. if (m_isRawDataConverted) return m_stringResult; switch (m_readType) { case ReadAsArrayBuffer: // No conversion is needed. break; case ReadAsBinaryString: m_stringResult = String(static_cast<const char*>(m_rawData->data()), m_bytesLoaded); break; case ReadAsText: convertToText(); break; case ReadAsDataURL: // Partial data is not supported when reading as data URL. if (isCompleted()) convertToDataURL(); break; default: ASSERT_NOT_REACHED(); } return m_stringResult; }
const ScriptString& FileReader::result() { // If reading as binary string, we can return the result immediately. if (m_readType == ReadFileAsBinaryString) return m_result; // If we already convert the raw data received so far, we can return the result now. if (m_isRawDataConverted) return m_result; m_isRawDataConverted = true; if (m_readType == ReadFileAsText) convertToText(); // For data URL, we only do the coversion until we receive all the raw data. else if (m_readType == ReadFileAsDataURL && m_state == Completed) convertToDataURL(m_rawData, m_fileType, m_result); return m_result; }