|
List Info
Thread: lostream to a file
|
|
| lostream to a file |

|
2007-09-04 17:03:23 |
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
Libpqxx-general gborg.postgresql.org
http://gborg.postgresql.org/mailman/listinfo/libpqxx
-general
|
|
| Re: lostream to a file |

|
2007-09-04 17:13:41 |
|
Try a look on this: http://www.cplusplus.com/doc/tutorial/files.html
On 9/4/07, Shannon Allen
< shannon.allen3 us.army.mil">shannon.allen3 us.army.mil> 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 Libpqxx-general gborg.postgresql.org">Libpqxx-general gborg.postgresql.org
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... -_-
|
| Re: lostream to a file |

|
2007-09-05 14:12:05 |
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 * <shannon.allen3 us.army.mil
> <mailto:shannon.allen3 us.army.mil>> 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
> Libpqxx-general gborg.postgresql.org
> <mailto:Libpqxx-general gborg.postgresql.org>
> 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
> Libpqxx-general gborg.postgresql.org
> http://gborg.postgresql.org/mailman/listinfo/libpqxx
-general
>
_______________________________________________
Libpqxx-general mailing list
Libpqxx-general gborg.postgresql.org
http://gborg.postgresql.org/mailman/listinfo/libpqxx
-general
|
|
| Re: lostream to a file |

|
2007-09-05 14:33:59 |
|
I'm not yet experienced with the library. However, some tests from test050.cxx to test065.cxx (provided with the sources) contain code samples handling large objects.
Good luck ;)
On 9/5/07, Shannon Allen < shannon.allen3 us.army.mil">shannon.allen3 us.army.mil> 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 * < shannon.allen3 us.army.mil">
shannon.allen3 us.army.mil > <mailto: shannon.allen3 us.army.mil">shannon.allen3 us.army.mil>> 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 > Libpqxx-general gborg.postgresql.org">Libpqxx-general gborg.postgresql.org > <mailto:
Libpqxx-general gborg.postgresql.org">Libpqxx-general gborg.postgresql.org> | |