Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
|
|
@ -1,5 +1 @@
|
|||
(define content (bytes->string
|
||||
(vec-iter
|
||||
(file->vector "file.txt"))))
|
||||
|
||||
(print content)
|
||||
(file->string "filename")
|
||||
|
|
|
|||
20
Task/Read-entire-file/Zig/read-entire-file-1.zig
Normal file
20
Task/Read-entire-file/Zig/read-entire-file-1.zig
Normal 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});
|
||||
}
|
||||
18
Task/Read-entire-file/Zig/read-entire-file-2.zig
Normal file
18
Task/Read-entire-file/Zig/read-entire-file-2.zig
Normal 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});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue