Add FileStream.truncate.

This commit is contained in:
Sönke Ludwig 2018-12-28 10:14:50 +01:00
parent 0d3338a16b
commit f35e8f1d69
2 changed files with 12 additions and 3 deletions

View file

@ -4,7 +4,7 @@ authors "Sönke Ludwig"
copyright "Copyright © 2016-2018, rejectedsoftware e.K."
license "MIT"
dependency "eventcore" version="~>0.8.39"
dependency "eventcore" version="~>0.8.40"
dependency "stdx-allocator" version="~>2.77.0"
targetName "vibe_core"

View file

@ -1,7 +1,7 @@
/**
File handling functions and types.
Copyright: © 2012-2016 RejectedSoftware e.K.
Copyright: © 2012-2018 RejectedSoftware e.K.
License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file.
Authors: Sönke Ludwig
*/
@ -13,7 +13,7 @@ import vibe.core.internal.release;
import vibe.core.log;
import vibe.core.path;
import vibe.core.stream;
import vibe.internal.async : asyncAwait;
import vibe.internal.async : asyncAwait, asyncAwaitUninterruptible;
import core.stdc.stdio;
import core.sys.posix.unistd;
@ -452,6 +452,15 @@ struct FileStream {
ulong tell() nothrow { return ctx.ptr; }
void truncate(ulong size)
{
auto res = asyncAwaitUninterruptible!(FileIOCallback,
cb => eventDriver.files.truncate(m_fd, size, cb)
);
enforce(res[1] == IOStatus.ok, "Failed to resize file.");
m_ctx.size = size;
}
/// Closes the file handle.
void close()
{