Hello Julian.
Recently, I’ve found out that the OutputStream class does not have a setSize method to truncate a file stream. This is natural for a file to be truncated at the end (e.g. to cut out a tag).
Could you, please, implement the method?
Hello Julian.
Recently, I’ve found out that the OutputStream class does not have a setSize method to truncate a file stream. This is natural for a file to be truncated at the end (e.g. to cut out a tag).
Could you, please, implement the method?
well… I’ll add it to my to-do list, though I can’t say I’ve ever needed to do that myself.
Well… if so, could you propose an optimal way to cut a certain amount of bytes out from the file end (or MemoryOutputStream) using the current JUCE implementation?
in a stream, you actually can’t predict if what you read or write has been written or kept in memory so far. best way is to read from a stream and write to another, while breaking at the point you want to cut.
[code]while (reading_from_input_stream_reach_end || my_cut_position_has_been_reached)
write_to_output_stream (input_stream_read);
close_output_stream[/code]
[quote=“kraken”]in a stream, you actually can’t predict if what you read or write has been written or kept in memory so far. best way is to read from a stream and write to another, while breaking at the point you want to cut.
[code]while (reading_from_input_stream_reach_end || my_cut_position_has_been_reached)
write_to_output_stream (input_stream_read);
close_output_stream[/code][/quote]
Well, kraken, I’d not call this approach “optimal”. Imagine it applied to a 8Gb files just to cut 1Kb at their end… Thanks, but it’s not suitable for me.
I’d rather create a platform specific function like this:
[code]void setFileSize(String file, int64 size)
{
#ifdef Windows
…open file with _wopen
…call _chsize
…_close file
#elif Linux
truncate(file.toUTF8(), size);
#endif
}[/code]
yeah sure, depends on your usage case (and how big are your files).
anyway that kind of stuff applies to the File class, not the Stream ones.
From my view, i can’t cut a stream like this, since “cutting a stream” for me simply means stopping reading from or writing to it.
[quote=“kraken”]anyway that kind of stuff applies to the File class, not the Stream ones.
From my view, i can’t cut a stream like this, since “cutting a stream” for me simply means stopping reading from or writing to it.[/quote]
I agree, you’re right. We need something like:
[code]static void File::setFileSize(String filePath, int64 size);
and
void File::setFileSize(int64 size);
[/code]
…but what about memory streams? Is there any way to resize a memory buffer? I think this is the matter of setting an internal member’s value to a new specified size. Am I wrong?