Beispiel #1
0
Result_t
ASDCP::TimedText::LocalFilenameResolver::ResolveRID(const byte_t* uuid, TimedText::FrameBuffer& FrameBuf) const
{
  Result_t result = RESULT_NOT_FOUND;
  char buf[64];
  UUID RID(uuid);
  PathList_t found_list;

  FindInPath(PathMatchRegex(RID.EncodeHex(buf, 64)), m_Dirname, found_list);

  if ( found_list.size() == 1 )
    {
      FileReader Reader;
      DefaultLogSink().Debug("retrieving resource %s from file %s\n", buf, found_list.front().c_str());

      result = Reader.OpenRead(found_list.front().c_str());

      if ( KM_SUCCESS(result) )
	{
	  ui32_t read_count, read_size = Reader.Size();
	  result = FrameBuf.Capacity(read_size);
      
	  if ( KM_SUCCESS(result) )
	    result = Reader.Read(FrameBuf.Data(), read_size, &read_count);

	  if ( KM_SUCCESS(result) )
	    FrameBuf.Size(read_count);
	}
    }
  else if ( ! found_list.empty() )
    {
      DefaultLogSink().Error("More than one file in %s matches %s.\n", m_Dirname.c_str(), buf);
      result = RESULT_RAW_FORMAT;
    }

  return result;
}
Beispiel #2
0
Kumu::Result_t
Kumu::ReadFileIntoString(const std::string& filename, std::string& outString, ui32_t max_size)
{
  fsize_t    fsize = 0;
  ui32_t     read_size = 0;
  FileReader File;
  ByteString ReadBuf;

  Result_t result = File.OpenRead(filename);

  if ( KM_SUCCESS(result) )
    {
      fsize = File.Size();

      if ( fsize > (Kumu::fpos_t)max_size )
	{
	  DefaultLogSink().Error("%s: exceeds available buffer size (%u)\n", filename.c_str(), max_size);
	  return RESULT_ALLOC;
	}

      if ( fsize == 0 )
	{
	  DefaultLogSink().Error("%s: zero file size\n", filename.c_str());
	  return RESULT_READFAIL;
	}

      result = ReadBuf.Capacity((ui32_t)fsize);
    }

  if ( KM_SUCCESS(result) )
    result = File.Read(ReadBuf.Data(), ReadBuf.Capacity(), &read_size);

  if ( KM_SUCCESS(result) )
    outString.assign((const char*)ReadBuf.RoData(), read_size);

  return result;
}