Stream Methods
Input and output streams are opened using a stream method. A stream method abstracts the stream operations required for reading or writing bytes from the source of those bytes. This makes it possible to read or write from data sources and storage mechanisms such as files, child processes, web servers, and in-memory lists of bytes. A stream method can also perform translations such as compression or encryption. For example, a stream method could allow a user to open a compressed file and read the uncompressed contents. Operating on streams allows operations to be performed on very large files that could otherwise not fit into physical memory.
The Wolfram System supplies stream methods for the most common needs, such as reading and writing from files, web servers, strings, and external commands. New stream methods can also be added to the Wolfram System.
When you open a stream for reading or writing, you can specify the stream method with the Method option, or the Wolfram System can choose the stream method automatically from the stream name.
In[1]:=1

✖
https://wolfram.com/xid/0ecs1k5f6pg-e9qpb7
Out[2]=2

In[3]:=3

✖
https://wolfram.com/xid/0ecs1k5f6pg-ikveh3
Out[3]=3

In[4]:=4

✖
https://wolfram.com/xid/0ecs1k5f6pg-dhf84z
Out[4]=4

This opens a stream from a web server, selecting the stream method with the Method option:
In[5]:=5

✖
https://wolfram.com/xid/0ecs1k5f6pg-hkk0m8
Out[6]=6

In[7]:=7

✖
https://wolfram.com/xid/0ecs1k5f6pg-b368uc
Out[7]=7

In[8]:=8

✖
https://wolfram.com/xid/0ecs1k5f6pg-c0vjkt
Out[8]=8

This loads a Wolfram System package directly from a web server, selecting the stream method from the stream name:
In[9]:=9

✖
https://wolfram.com/xid/0ecs1k5f6pg-jid3us
In[10]:=10

✖
https://wolfram.com/xid/0ecs1k5f6pg-jur6ve
Out[10]=10

This loads a Wolfram System package directly from a web server, using an explicitly opened input stream:
In[11]:=11

✖
https://wolfram.com/xid/0ecs1k5f6pg-mdc9qd
Out[11]=11

In[12]:=12

✖
https://wolfram.com/xid/0ecs1k5f6pg-hnqb2n
In[13]:=13

✖
https://wolfram.com/xid/0ecs1k5f6pg-fby35p
In[14]:=14

✖
https://wolfram.com/xid/0ecs1k5f6pg-g701ik
Out[14]=14

In[15]:=15

✖
https://wolfram.com/xid/0ecs1k5f6pg-eqcdw
Out[15]=15

You can add new input stream methods to the Wolfram System. This would be useful if you wanted to read from a new storage medium, or you wanted to transform the data as it is read, such as uncompressing a file.
Define a stream method that takes its input not from a file but from a list of bytes, passed as a method option "Bytes":
In[16]:=16

✖
https://wolfram.com/xid/0ecs1k5f6pg-vx3it
Out[16]=16

In[17]:=17

✖
https://wolfram.com/xid/0ecs1k5f6pg-b00ha2

This defines a stream method that performs a rotation cipher on the stream as it reads. A cryptographically strong decryption could be performed in the same fashion:
In[21]:=21

✖
https://wolfram.com/xid/0ecs1k5f6pg-fk4y6v
Out[23]=23

In[24]:=24

✖
https://wolfram.com/xid/0ecs1k5f6pg-p5ddg4
Out[24]=24

In[26]:=26

✖
https://wolfram.com/xid/0ecs1k5f6pg-bp92wu
Out[26]=26

The file content differs from what Read returns, because the stream method translates it:
In[27]:=27

✖
https://wolfram.com/xid/0ecs1k5f6pg-eef2
Out[27]=27

In[28]:=28

✖
https://wolfram.com/xid/0ecs1k5f6pg-j98gk
Out[28]=28

You can add new output stream methods to the Wolfram System. This would be useful if you wanted to write to a new storage medium, or you wanted to transform the data as it is written, such as compressing a file.
In[30]:=30

✖
https://wolfram.com/xid/0ecs1k5f6pg-ef1xm8
Out[30]=30

In[31]:=31

✖
https://wolfram.com/xid/0ecs1k5f6pg-e0x19z
Out[31]=31

In[32]:=32

✖
https://wolfram.com/xid/0ecs1k5f6pg-cxrvwt
Out[32]=32

In[33]:=33

✖
https://wolfram.com/xid/0ecs1k5f6pg-jkicq8
Out[33]=33

In[34]:=34

✖
https://wolfram.com/xid/0ecs1k5f6pg-eksyl
Out[34]=34

In[35]:=35

✖
https://wolfram.com/xid/0ecs1k5f6pg-etsddg
Out[35]=35

In[36]:=36

✖
https://wolfram.com/xid/0ecs1k5f6pg-jielme