SHARE
TWEET

Untitled

a guest May 23rd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const std = @import("std");
  2. const os = std.os;
  3. const warn = std.debug.warn;
  4.  
  5. pub fn main() !void {
  6.     var file = try os.File.openRead("/path/to/file.txt");
  7.     defer file.close();
  8.  
  9.     const file_size = try file.getEndPos();
  10.     // why cant I use?
  11.     // var buffer: [file_size]u8 = undefined;
  12.     // ie, I only want to create a buffer that is same size as
  13.     // the file been read.
  14.  
  15.     var buffer: [1024 * 4]u8 = undefined;
  16.     const bytes_read = try file.read(buffer[0..buffer.len]);
  17.     warn("{}", buffer[0..bytes_read]);
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top