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:
commit
e5d53249fc
2
dub.sdl
2
dub.sdl
|
@ -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"
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue