mirror of
https://github.com/ksherlock/profuse.git
synced 2025-02-06 15:30:08 +00:00
fix compression, add setFileSize()
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@311 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
f81205b63f
commit
96f1de7206
@ -254,9 +254,7 @@ int FileEntry::truncateCommon(unsigned newSize)
|
||||
|
||||
}
|
||||
|
||||
_lastBlock = 1 + _firstBlock + newSize / 512;
|
||||
_lastByte = newSize % 512;
|
||||
if (_lastByte == 0) _lastByte = 512;
|
||||
setFileSize(newSize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -293,8 +291,8 @@ int FileEntry::write(TextWriter &text)
|
||||
}
|
||||
|
||||
_modification = Date::Today();
|
||||
_lastBlock = 1 + firstBlock() + blocks;
|
||||
_lastByte = 512;
|
||||
|
||||
setFileSize(blocks * 512);
|
||||
|
||||
parent()->writeEntry(this);
|
||||
parent()->sync();
|
||||
@ -302,7 +300,7 @@ int FileEntry::write(TextWriter &text)
|
||||
return blocks * 512;
|
||||
}
|
||||
|
||||
int FileEntry::write(uint8_t *buffer, unsigned size, unsigned offset)
|
||||
int FileEntry::write(const uint8_t *buffer, unsigned size, unsigned offset)
|
||||
{
|
||||
#undef __METHOD__
|
||||
#define __METHOD__ "FileEntry::write"
|
||||
@ -368,13 +366,9 @@ int FileEntry::write(uint8_t *buffer, unsigned size, unsigned offset)
|
||||
block++;
|
||||
}
|
||||
|
||||
if (newSize > currentSize)
|
||||
{
|
||||
_lastBlock = 1 + _firstBlock + currentSize / 512;
|
||||
_lastByte = currentSize % 512;
|
||||
if (_lastByte == 0) _lastByte = 512;
|
||||
|
||||
}
|
||||
|
||||
if (newSize > currentSize) setFileSize(newSize);
|
||||
|
||||
|
||||
_modification = Date::Today();
|
||||
parent()->writeEntry(this);
|
||||
@ -383,6 +377,26 @@ int FileEntry::write(uint8_t *buffer, unsigned size, unsigned offset)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* private
|
||||
* set the file size. Does not check if > _maxFileSize.
|
||||
*
|
||||
*/
|
||||
void FileEntry::setFileSize(unsigned size)
|
||||
{
|
||||
if (size == 0)
|
||||
{
|
||||
// TODO -- verify how 0 byte files are handled.
|
||||
_lastBlock = _firstBlock + 1;
|
||||
_lastByte = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
_lastBlock = 1 + _firstBlock + size / 512;
|
||||
_lastByte = size % 512;
|
||||
if (_lastByte == 0) _lastByte = 512;
|
||||
}
|
||||
|
||||
unsigned FileEntry::dataFileSize()
|
||||
{
|
||||
return blocks() * 512 - 512 + _lastByte;
|
||||
@ -633,12 +647,14 @@ bool FileEntry::Compress(std::string& text)
|
||||
|
||||
if (count < 3) return false;
|
||||
|
||||
count = std::max((int)count, 255 - 32);
|
||||
count = std::min((int)count, 255 - 32);
|
||||
|
||||
out.push_back(kDLE);
|
||||
out.push_back(32 + count);
|
||||
out.append(text.begin() + count, text.end());
|
||||
|
||||
text.swap(out);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -662,6 +678,7 @@ bool FileEntry::Uncompress(std::string& text)
|
||||
out.append(c - 32, ' ');
|
||||
out.append(text.begin() + 2, text.end());
|
||||
|
||||
text.swap(out);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ namespace Pascal {
|
||||
void setFileKind(unsigned kind);
|
||||
|
||||
int read(uint8_t *buffer, unsigned size, unsigned offset);
|
||||
int write(uint8_t *buffer, unsigned size, unsigned offset);
|
||||
int write(const uint8_t *buffer, unsigned size, unsigned offset);
|
||||
|
||||
int write(TextWriter& text);
|
||||
|
||||
@ -58,7 +58,7 @@ namespace Pascal {
|
||||
|
||||
int truncateCommon(unsigned newSize);
|
||||
|
||||
|
||||
void setFileSize(unsigned size);
|
||||
|
||||
unsigned _status;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user