title: How to create a Stream from reading and transforming a file?
body: <p>I'm trying to read a file, decrypt it, and return the data. Because the file is potentially very big, I want to do this in a stream.</p>
  
  <p>I cannot find a good pattern to implement the stream. I'm trying to do something like this: </p>
  
  <pre><code>let stream = stream::unfold(decrypted_init_length, |decrypted_length| async move {
      if decrypted_length &lt; start + length {
          let mut encrypted_chunk = vec![0u8; encrypted_block_size];
          match f.read(&amp;mut encrypted_chunk[..]) {
              Ok(size) =&gt; {
                  if size &gt; 0 {
                      let decrypted = my_decrypt_fn(&amp;encrypted_chunk[..]);
                      let updated_decrypted_length = decrypted_length + decrypted.len();
                      Some((decrypted, updated_decrypted_length))
                  } else {
                      None
                  }
              }
              Err(e) =&gt; {
                  println!("Error {}", e);
                  None
              }
          }
      } else {
          None
      }
  });
  </code></pre>
  
  <p>The problem is that <code>f.read</code> is not allowed in the above async closure with the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>89  | |             match f.read(&amp;mut encrypted_chunk[..]) {
      | |                   -
      | |                   |
      | |                   move occurs because `f` has type `std::fs::File`, which does not implement the `Copy` trait
      | |                   move occurs due to use in generator
  </code></pre>
  
  <p>I don't want to open <code>f</code> inside the closure itself. Is there any better way to fix this?  I am OK with using a different crate or trait, or method (i.e. not <code>stream::unfold</code>).</p>