Merge pull request #113 from vibe-d/file_truncate

Add FileStream.truncate
merged-on-behalf-of: Sönke Ludwig <s-ludwig@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2018-12-28 14:03:19 +01:00 committed by GitHub
commit e5d53249fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;
@ -453,6 +453,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()
{