Bug 17912 – Add function to std.file for creating a temporary file with a name

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-10-17T23:15:39Z
Last change time
2024-12-01T16:30:58Z
Assigned to
No Owner
Creator
Jonathan M Davis
Moved to GitHub: phobos#9722 →

Comments

Comment #0 by issues.dlang — 2017-10-17T23:15:39Z
We previously added a function to std.stdio for safely creating a temporary file with a name that could be closed and reopened (unlike std.stdio.File.tmpfile, which has no name and is deleted when it's closed), but it was removed due to the fact that it increased the size of hello world even though it arguably shouldn't have: https://issues.dlang.org/show_bug.cgi?id=14599 I propose that instead of waiting for the compiler to be improved to the point that we can re-add scratchFile to std.stdio without increasing the size of hell world, we add a function to std.file which creates a temporary file and returns its name. It does have the downside that you have to reopen the file if you want to use it with std.stdio.File, but it could optionally accept data like std.file.write does so that it can be created with data rather than having to create it and then reopen it to write to it. And for many (most?) cases where you want a temporary file with a name to be operating on, this arrangement would probably work better than getting a std.stdio.File to write to anyway (e.g. a major use case is creating a temporary file for unit tests where you need a file to read and write to using its name).
Comment #1 by issues.dlang — 2017-10-22T19:13:40Z
Comment #2 by robert.schadek — 2024-12-01T16:30:58Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/9722 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB