Compare commits
No commits in common. "fastb64z" and "main" have entirely different histories.
3 changed files with 6 additions and 14 deletions
|
@ -6,11 +6,9 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
const clap_dep = b.dependency("clap", .{ .target = target, .optimize = optimize });
|
const clap_dep = b.dependency("clap", .{ .target = target, .optimize = optimize });
|
||||||
const clap = clap_dep.module("clap");
|
const clap = clap_dep.module("clap");
|
||||||
const fastb64z_dep = b.dependency("fastb64z", .{ .target = target, .optimize = optimize });
|
|
||||||
const fastb64z = fastb64z_dep.module("fastb64z");
|
|
||||||
|
|
||||||
var opt = b.addOptions();
|
var opt = b.addOptions();
|
||||||
opt.addOption([]const u8, "version", "0.0.3");
|
opt.addOption([]const u8, "version", "0.0.2");
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = "b64",
|
.name = "b64",
|
||||||
.root_source_file = b.path("src/main.zig"),
|
.root_source_file = b.path("src/main.zig"),
|
||||||
|
@ -19,7 +17,6 @@ pub fn build(b: *std.Build) void {
|
||||||
});
|
});
|
||||||
exe.root_module.addImport("build_info", opt.createModule());
|
exe.root_module.addImport("build_info", opt.createModule());
|
||||||
exe.root_module.addImport("clap", clap);
|
exe.root_module.addImport("clap", clap);
|
||||||
exe.root_module.addImport("fastb64z", fastb64z);
|
|
||||||
b.installArtifact(exe);
|
b.installArtifact(exe);
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
run_cmd.step.dependOn(b.getInstallStep());
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
|
|
@ -4,10 +4,6 @@
|
||||||
.paths = .{""},
|
.paths = .{""},
|
||||||
.minimum_zig_version = "0.13.0",
|
.minimum_zig_version = "0.13.0",
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.fastb64z = .{
|
|
||||||
.url = "https://github.com/joadnacer/fastb64z/archive/17f00616b661efa6e02065c4c9a0e7b4682e0a16.tar.gz",
|
|
||||||
.hash = "1220e16c6b41749367d8663ba8acc356fdafce8b0fef40edb59ce0525e0683392eda",
|
|
||||||
},
|
|
||||||
.clap = .{
|
.clap = .{
|
||||||
.url = "https://github.com/Hejsil/zig-clap/archive/master/latest.tar.gz",
|
.url = "https://github.com/Hejsil/zig-clap/archive/master/latest.tar.gz",
|
||||||
.hash = "1220c900c70daf3e715fad6f266ec14b1d0f5e6c2d3f34b32142f60306cb9b5e5f05",
|
.hash = "1220c900c70daf3e715fad6f266ec14b1d0f5e6c2d3f34b32142f60306cb9b5e5f05",
|
||||||
|
|
11
src/main.zig
11
src/main.zig
|
@ -2,7 +2,6 @@ const std = @import("std");
|
||||||
const clap = @import("clap");
|
const clap = @import("clap");
|
||||||
const build_info = @import("build_info");
|
const build_info = @import("build_info");
|
||||||
const base64 = std.base64;
|
const base64 = std.base64;
|
||||||
const fastb64z = @import("fastb64z");
|
|
||||||
const debug = std.debug;
|
const debug = std.debug;
|
||||||
const io = std.io;
|
const io = std.io;
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ pub fn main() !void {
|
||||||
const encoded = try encode(allocator, input.items);
|
const encoded = try encode(allocator, input.items);
|
||||||
defer allocator.free(encoded);
|
defer allocator.free(encoded);
|
||||||
|
|
||||||
try stdout.writer().print("{s}\n", .{encoded});
|
try stdout.writer().print("{s}", .{encoded});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +121,7 @@ fn version() void {
|
||||||
fn read_from_stream(allocator: std.mem.Allocator, stream: std.fs.File) !std.ArrayList(u8) {
|
fn read_from_stream(allocator: std.mem.Allocator, stream: std.fs.File) !std.ArrayList(u8) {
|
||||||
var input = std.ArrayList(u8).init(allocator);
|
var input = std.ArrayList(u8).init(allocator);
|
||||||
|
|
||||||
var fifo = std.fifo.LinearFifo(u8, .{ .Static = 8192 }).init();
|
var fifo = std.fifo.LinearFifo(u8, .{ .Static = 1024 }).init();
|
||||||
|
|
||||||
try fifo.pump(stream.reader(), input.writer());
|
try fifo.pump(stream.reader(), input.writer());
|
||||||
defer fifo.deinit();
|
defer fifo.deinit();
|
||||||
|
@ -131,7 +130,7 @@ fn read_from_stream(allocator: std.mem.Allocator, stream: std.fs.File) !std.Arra
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode(allocator: std.mem.Allocator, string: []const u8) ![]const u8 {
|
fn encode(allocator: std.mem.Allocator, string: []const u8) ![]const u8 {
|
||||||
const encoder = fastb64z.standard.Encoder;
|
const encoder = std.base64.standard.Encoder;
|
||||||
const encoded = try allocator.alloc(u8, encoder.calcSize(string.len));
|
const encoded = try allocator.alloc(u8, encoder.calcSize(string.len));
|
||||||
|
|
||||||
defer allocator.free(encoded);
|
defer allocator.free(encoded);
|
||||||
|
@ -142,7 +141,7 @@ fn encode(allocator: std.mem.Allocator, string: []const u8) ![]const u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decode(allocator: std.mem.Allocator, b64string: []const u8) ![]u8 {
|
fn decode(allocator: std.mem.Allocator, b64string: []const u8) ![]u8 {
|
||||||
const decoder = fastb64z.standard.Decoder;
|
const decoder = std.base64.standard.Decoder;
|
||||||
const decodeSize = decoder.calcSizeForSlice(b64string) catch |err| {
|
const decodeSize = decoder.calcSizeForSlice(b64string) catch |err| {
|
||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
@ -153,7 +152,7 @@ fn decode(allocator: std.mem.Allocator, b64string: []const u8) ![]u8 {
|
||||||
|
|
||||||
defer allocator.free(decoded);
|
defer allocator.free(decoded);
|
||||||
|
|
||||||
decoder.decodeFast(decoded, b64string) catch |err| {
|
decoder.decode(decoded, b64string) catch |err| {
|
||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue