Data update

This commit is contained in:
Ingy döt Net 2023-12-16 21:33:55 -08:00
parent 35bcdeebf8
commit 74c69a0df6
2427 changed files with 31826 additions and 3468 deletions

View file

@ -1,5 +1 @@
(define content (bytes->string
(vec-iter
(file->vector "file.txt"))))
(print content)
(file->string "filename")

View file

@ -0,0 +1,20 @@
const std = @import("std");
const File = std.fs.File;
pub fn main() (error{OutOfMemory} || File.OpenError || File.ReadError)!void {
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .{};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const cwd = std.fs.cwd();
var file = try cwd.openFile("input_file.txt", .{ .mode = .read_only });
defer file.close();
const file_content = try file.readToEndAlloc(allocator, comptime std.math.maxInt(usize));
defer allocator.free(file_content);
std.debug.print("Read {d} octets. File content:\n", .{file_content.len});
std.debug.print("{s}", .{file_content});
}

View file

@ -0,0 +1,18 @@
const std = @import("std");
const File = std.fs.File;
pub fn main() (File.OpenError || File.SeekError || std.os.MMapError)!void {
const cwd = std.fs.cwd();
var file = try cwd.openFile("input_file.txt", .{ .mode = .read_only });
defer file.close();
const file_size = (try file.stat()).size;
const file_content = try std.os.mmap(null, file_size, std.os.PROT.READ, std.os.MAP.PRIVATE, file.handle, 0);
defer std.os.munmap(file_content);
std.debug.print("Read {d} octets. File content:\n", .{file_content.len});
std.debug.print("{s}", .{file_content});
}