Update:

Getting closer.  I can now get the size of the lostream and it matches 
the size of the file before I put it into the BLOB.  The problem I'm 
having now is when I go to write the lostream back out to a file, in 
Linux whenever I do a cmp originalfile newfile, it says that they are 
different ("differ: byte 2590721, line 35").  But the sizes match 
exactly.  Anyone have any idea??


   std::string me = "blobStream";  
   pqxx::work w(*atr->getConn(),me);
   pqxx::ilostream s(w, 137396206);

   ofstream file("test.seqb", ios::out|ios::binary|ios::trunc);
   pqxx::ilostream ::pos_type size;
   char * memblock(0);
  
   cout << "Streaming blob into a file " << endl;
   if(s.good())
   {
      s.seekg (0, ios::end);
      size = s.tellg();
      cout << "SIZE OF LOSTREAM " << size << endl;
      memblock = new char [size];
      s.seekg (0, ios::beg);
      s.read (memblock, size);
      file.seekp(0,ios::beg);
      file.write(memblock,size);
      delete[] memblock;
      file.close();
   }
   cout << "Done Streaming blob into a file " << endl;


>
>
>
> On 9/5/07, *Shannon Allen* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>     Can you tell what I am missing?  s.tellg() returns a size of 0.  I
>     know
>     there is a largeobject there with that id, because I can do this right
>     before the below code and it works perfecltly:
>       pqxx::largeobjectaccess loGet(w,137396206,PGSTD::ios::in);
>       loGet.to_file("test.seqb");
>
>
>       ...
>        pqxx::work w(*atr->getConn(),me);
>       pqxx::ilostream s(w, 137396206);
>
>       ofstream file("test.seqb", ios::out|ios::binary|ios::trunc);
>       pqxx::ilostream::pos_type size;
>       char * memblock(0);
>
>       cout << "Streaming blob into a file " << endl;
>       if(s.good())
>       {
>          size = s.tellg();
>          cout << "SIZE OF LOSTREAM " << size << endl;   ==> prints out 0
>          memblock = new char [size];
>          s.seekg (0, ios::beg);
>          s.read (memblock, size);
>          file.write(memblock,size);
>          delete[] memblock;
>          file.close();
>       }
>
>
>     Thanks.
>
>     Hilton Perantunes wrote:
>     > Try a look on this:
>     > http://www.cplusplus.com/doc/tutorial/files.html
>     >
>     >
>     >
>     > On 9/4/07, *Shannon Allen * < [EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>
>     > <mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>>> wrote:
>     >
>     >     I am trying to get comfortable using the lostream class for
>     large
>     >     objects.  I have a large binary file that I am storing in a BLOB
>     >     that I
>     >     can get back out using largeobjectaccess and then use the
>     >     to_file(file)
>     >     method to write it back out and that works fine.  However, I
>     want to
>     >     give users streaming functionality, but I need to know how
>     to do it
>     >     first :-) .
>     >
>     >     What I would like to do first is stream this back out to a file,
>     >     similar
>     >     to what I've already done with
>     largeobjectaccess::to_file(file), but
>     >     instead I want to use lostream.
>     >
>     >     Given this code, what do I need to do next?
>     >
>     >     ...
>     >        pqxx::work w(*atr->getConn(),me);
>     >        pqxx::ilostream s(w, id5);
>     >
>     >        ofstream file("test.seqb", ios::out | ios::binary |
>     ios::trunc);
>     >        cout << "Streaming blob into a file " << endl;
>     >
>     >        //This isn't right
>     >        if(s.good())
>     >        {
>     >           file << s;
>     >        }
>     >        cout << "Done Streaming blob into a file " << endl;
>     >        file.close();
>     >     ...
>     >     _______________________________________________
>     >     Libpqxx-general mailing list
>     >     [email protected]
>     <mailto:[email protected]>
>     >     <mailto: [email protected]
>     <mailto:[email protected]>>
>     >     http://gborg.postgresql.org/mailman/listinfo/libpqxx-general
>     <http://gborg.postgresql.org/mailman/listinfo/libpqxx-general>
>     >
>     >
>     >
>     >
>     > --
>     > Hilton William Ganzo Perantunes
>     > Sistemas de Informação - Universidade Federal de Santa Catarina
>     > --
>     > Dinheiro não traz felicidade, mas dá uma sensação tão
>     parecida...  -_-
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > Libpqxx-general mailing list
>     > [email protected]
>     <mailto:[email protected]>
>     > http://gborg.postgresql.org/mailman/listinfo/libpqxx-general
>     >
>
>     _______________________________________________
>     Libpqxx-general mailing list
>     [email protected]
>     <mailto:[email protected]>
>     http://gborg.postgresql.org/mailman/listinfo/libpqxx-general
>     <http://gborg.postgresql.org/mailman/listinfo/libpqxx-general>
>
>
>
>
> -- 
> Hilton William Ganzo Perantunes
> Sistemas de Informação - Universidade Federal de Santa Catarina
> --
> Dinheiro não traz felicidade, mas dá uma sensação tão parecida...  -_-
> ------------------------------------------------------------------------
>
> _______________________________________________
> Libpqxx-general mailing list
> [email protected]
> http://gborg.postgresql.org/mailman/listinfo/libpqxx-general
>   

_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general

Reply via email to