Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use with a growing buffer #50

Open
aminya opened this issue Jul 11, 2021 · 3 comments
Open

Use with a growing buffer #50

aminya opened this issue Jul 11, 2021 · 3 comments
Labels

Comments

@aminya
Copy link

aminya commented Jul 11, 2021

How can I use this package with a growing buffer?

I tried a dynamic array, but it doesn't work

    ubyte[] buf;
    auto file = File(filePath, Mode.readWrite);
    file.read(buf);

    import std: writeln;
    writeln(buf); // buf is empty
@schveiguy
Copy link
Owner

This package does not do buffering, it is strictly an abstraction of an i/o subsystem, and the basis of other packages which might do buffering or whatever else. If you want buffering, I'd suggest using iopipe which is built to work on top of this package, and provides a buffering system.

Your code basically says "read 0 bytes from the input", and then writes that empty buffer to stdout.

@aminya
Copy link
Author

aminya commented Jul 11, 2021

I couldn't find a simple example that allows me to read text from a file. I want to see if this library gives better performance over the following code that I have.

   import std.file : readText, write;

   const string str = readText(file);
   const strModified = doThingsWithString(str);
   write(file, strModified);

@schveiguy
Copy link
Owner

read and readText use the file size to preallocate the result. I doubt you get better performance by using a growing buffer. I also wouldn’t expect much performance difference with std.io if you did the same optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants