Fixed insertion of files into an existing archive
This commit is contained in:
parent
1e0af60669
commit
f44ecb1f65
@ -17,54 +17,39 @@
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <streambuf>
|
||||
#include <locale>
|
||||
#include <cstdio>
|
||||
|
||||
class proxy_streambuf : public std::streambuf
|
||||
{
|
||||
public:
|
||||
|
||||
proxy_streambuf(std::streambuf* streambuf, unsigned int numChars):
|
||||
_streambuf(streambuf),
|
||||
_numChars(numChars) {}
|
||||
|
||||
/// Destructor deallocates no buffer space.
|
||||
virtual ~proxy_streambuf() {}
|
||||
|
||||
std::streambuf* _streambuf;
|
||||
unsigned int _numChars;
|
||||
|
||||
protected:
|
||||
|
||||
virtual int_type uflow ()
|
||||
{
|
||||
if (_numChars==0) return -1;
|
||||
--_numChars;
|
||||
return _streambuf->sbumpc();
|
||||
}
|
||||
};
|
||||
#include <iostream>
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
/*
|
||||
std::ifstream fin("GNUmakefile");
|
||||
std::istream& ins = fin;
|
||||
|
||||
proxy_streambuf mystreambuf(ins.rdbuf(),10000);
|
||||
ins.rdbuf(&mystreambuf);
|
||||
|
||||
while (!fin.eof())
|
||||
std::fstream fout("test.data",std::ofstream::out | std::ofstream::binary);
|
||||
unsigned int numCharacters = 26;
|
||||
char baseCharacter = 'A';
|
||||
|
||||
for(unsigned int i=0;i<numCharacters;++i)
|
||||
{
|
||||
std::cout.put(fin.get());
|
||||
char c = baseCharacter + i;
|
||||
fout.write(&c,1);
|
||||
}
|
||||
std::cout<<"Exiting normally "<<std::endl;
|
||||
fout.close();
|
||||
|
||||
ins.rdbuf(mystreambuf._streambuf);
|
||||
*/
|
||||
fout.open("test.data",std::ofstream::out | std::ofstream::in | std::ofstream::binary);
|
||||
|
||||
char offset = 'a'-'A';
|
||||
unsigned int start_range = 5;
|
||||
unsigned int end_range = 15;
|
||||
|
||||
fout.seekp(start_range);
|
||||
for(unsigned int i=start_range;i<end_range;++i)
|
||||
{
|
||||
char c = (baseCharacter + i)+offset ;
|
||||
fout.write(&c,1);
|
||||
}
|
||||
|
||||
fout.close();
|
||||
|
||||
*/
|
||||
// use an ArgumentParser object to manage the program arguments.
|
||||
osg::ArgumentParser arguments(&argc,argv);
|
||||
|
||||
|
@ -134,7 +134,7 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
||||
float _version;
|
||||
Status _status;
|
||||
std::ifstream _input;
|
||||
std::ofstream _output;
|
||||
std::fstream _output;
|
||||
|
||||
IndexBlockList _indexBlockList;
|
||||
FileNamePositionMap _indexMap;
|
||||
|
@ -247,27 +247,16 @@ bool Archive::open(const std::string& filename, Status status, unsigned int inde
|
||||
if (status==WRITE && open(filename,READ))
|
||||
{
|
||||
_input.close();
|
||||
|
||||
struct stat results;
|
||||
pos_type end_of_file = 0;
|
||||
if (stat(filename.c_str(), &results) == 0)
|
||||
{
|
||||
// The size of the file in bytes is in
|
||||
// results.st_size
|
||||
end_of_file = results.st_size;
|
||||
}
|
||||
|
||||
_status = WRITE;
|
||||
|
||||
_output.open(filename.c_str(), std::ios_base::binary | std::ios_base::out);
|
||||
_output.open(filename.c_str(), std::ios_base::binary | std::ios_base::in | std::ios_base::out);
|
||||
|
||||
|
||||
|
||||
osg::notify(osg::NOTICE)<<"File position after open = "<<(int)_output.tellp()<<" is_open "<<_output.is_open()<<std::endl;
|
||||
|
||||
// place write position at end of file.
|
||||
//_output.seekp(0,std::ios::end);
|
||||
_output.seekp(end_of_file, std::ios::end);
|
||||
_output.seekp(0, std::ios::end);
|
||||
|
||||
|
||||
osg::notify(osg::NOTICE)<<"File position after seekp = "<<(int)_output.tellp()<<std::endl;
|
||||
@ -497,7 +486,7 @@ ReaderWriter::WriteResult Archive::writeObject(const osg::Object& obj,const std:
|
||||
osg::notify(osg::NOTICE)<<"Archive::writeObject(obj, "<<fileName<<")"<<std::endl;
|
||||
|
||||
// place write position at end of file.
|
||||
// _output.seekp(0,std::ios::end);
|
||||
_output.seekp(0,std::ios::end);
|
||||
|
||||
pos_type position = _output.tellp();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user