Questions tagged [io]

In computing, input/output, or I/O, refers to the communication between an information processing system (such as a computer), and the outside world, possibly a human, or another information processing system.

In computing, input/output, or I/O, refers to the communication between an information processing system (such as a computer), and the outside world, possibly a human, or another information processing system.

(Source: Wikipedia [Input/Output])


I/O includes tasks such as:

  • Reading and writing files ()
  • Interacting with a user through a command-line terminal session ( / / )
  • Connecting programs so that one sends its output to the next (s)
  • Sending data over a network in packets or as a data stream ()

For the Io language, see

17482 questions
6
votes
1 answer

Why does an io.reader become empty after reading it?

func foo(buf *bytes.Buffer) { fmt.Println("0: ", len(buf.Bytes())) ioutil.ReadAll(buf) fmt.Println("1: ", len(buf.Bytes())) } The code shows the correct length the first time, but the second times it shows the length is zero.
joy
  • 85
  • 1
  • 4
6
votes
0 answers

Writing and Parsing Binary Data in NodeJs

So i wrote server tcp application with nodejs, here is the code: Server Side var host = "127.0.0.1"; var port = 15010; // Instruct server to start Listening for incoming connection function listen() { // Start Server console.log('Server…
CXO2
  • 628
  • 10
  • 28
6
votes
1 answer

How to read, filter and modify lines from a file

How to do something similar to this D and Java code in Rust? Java: import java.nio.file.*; import java.io.*; public class Main { public static void main( String[] args ) throws IOException { …
Kozzi11
  • 2,413
  • 12
  • 17
6
votes
2 answers

What is the magic behind perl read() function and buffer which is not a ref?

I do not get to understand how the Perl read($buf) function is able to modify the content of the $buf variable. $buf is not a reference, so the parameter is given by copy (from my c/c++ knowledge). So how come the $buf variable is modified in the…
Alex F
  • 826
  • 8
  • 18
6
votes
4 answers

Why is buffered I/O faster than unbuffered I/O

While reading this, I found a reasonable answer, which says: Case 1: Directly Writing to File On Disk 100 times x 1 ms = 100 ms I understood that. Next, Case 3: Buffering in Memory before Writing to File on Disk (100 times x 0.5 ms) + 1 ms…
cengizhan
  • 85
  • 2
  • 6
6
votes
2 answers

What level are fread thread locks on? What level do they need to be on?

Visual Studio's fread "locks out other threads." There is an alternate version _fread_nolock, which reads "without locking other threads", which should only be used "in thread-safe contexts such as single-threaded applications or where the calling…
user1902689
  • 1,655
  • 2
  • 22
  • 33
6
votes
1 answer

Why is ifstream::read much faster than using iterators?

As it is, there are many approaches to reading a file into a string. Two common ones are using ifstream::read to read directly to a string and using steambuf_iterators along with std::copy_n: Using ifstream::read: std::ifstream in…
Veritas
  • 2,150
  • 3
  • 16
  • 40
6
votes
2 answers

Why does io.WriterTo's WriteTo method return an int64 rather than an int?

Most of the output methods in Go's io package return (int, error), for example io.Writer's Write([]byte) method and the io.WriteString(io.Writer, string) function. However, a few of the output methods, such as io.WriterTo's WriteTo method, return…
Matt
  • 21,026
  • 18
  • 63
  • 115
6
votes
3 answers

How to use 'fixed' floatfield for istream/istringstream?

C++ has an I/O manipulator called 'fixed' to input/output floating-point numbers in fixed (non-scientific) form. It works fine for output, but I don't understand how to get input working properly. Consider this example: #include #include…
JIghtuse
  • 866
  • 5
  • 11
6
votes
3 answers

cannot switch to blocking mode using fcntl in linux

I have a sample program: int main() { const char* fn = "/tmp/tmpfifo"; int i = mkfifo(fn, 0666); int fd = open(fn, O_RDONLY | O_NONBLOCK); int flags = fcntl(fd, F_GETFL); flags &= ~O_NONBLOCK; fcntl(fd, F_SETFL, flags); char…
hovnatan
  • 1,331
  • 10
  • 23
6
votes
1 answer

In perl6, how do you read a file in paragraph mode?

data.txt: hello world goodbye mars goodbye perl6 hello perl5 myprog.py: my $fname = 'data.txt'; my $infile = open($fname, :r, nl => "\n\n"); for $infile.lines(nl => "\n\n") -> $para { say $para; say '-' x 10; } Actual output: hello…
7stud
  • 46,922
  • 14
  • 101
  • 127
6
votes
2 answers

What does rdstate() return value mean?

istream& Read(istream &is) { std::string buf; while (is >> buf) { cout << is.eofbit << " " << is.failbit << " " << is.badbit << endl; cout << is.rdstate() << endl; cout << buf << endl; } cout <<…
Ocxs
  • 149
  • 2
  • 10
6
votes
2 answers

ObjectMapper append file JSON

Trying to learn about Jackson some, so I'm writing a simple program that reads a file/creates one to store some JSON in it. From the Jackson website I figured out how to read and write from the file, but in the case of my rudimentary program, i'd…
erp
  • 2,950
  • 9
  • 45
  • 90
6
votes
2 answers

How is a file handle closed when it goes out of scope?

I don't understand what Rust does with a file handle when it goes out of scope. For example, I create a file and write several words into it: let wd = os::getcwd().unwrap_or(Path::new("/")); let mut file =…
mkrakhin
  • 3,386
  • 1
  • 21
  • 34
6
votes
1 answer

python PIL image how to save image to a buffer so can be used later?

I have a png file which should be convert to jpg and save to gridfs , I use python's PIL lib to load the file and do the converting job, the problem is I want to store the converted image to a MongoDB Gridfs, in the saving procedure, I can't just…
armnotstrong
  • 8,605
  • 16
  • 65
  • 130