forked from vieter-v/vieter
refactor: compile on V 0.3.2
This commit is contained in:
parent
ed29102717
commit
22fd6e395b
23 changed files with 205 additions and 203 deletions
|
|
@ -5,7 +5,7 @@ import io
|
|||
import os
|
||||
|
||||
// reader_to_writer tries to consume the entire reader & write it to the writer.
|
||||
pub fn reader_to_writer(mut reader io.Reader, mut writer io.Writer) ? {
|
||||
pub fn reader_to_writer(mut reader io.Reader, mut writer io.Writer) ! {
|
||||
mut buf := []u8{len: 10 * 1024}
|
||||
|
||||
for {
|
||||
|
|
@ -21,8 +21,8 @@ pub fn reader_to_writer(mut reader io.Reader, mut writer io.Writer) ? {
|
|||
}
|
||||
|
||||
// reader_to_file writes the contents of a BufferedReader to a file
|
||||
pub fn reader_to_file(mut reader io.BufferedReader, length int, path string) ? {
|
||||
mut file := os.create(path)?
|
||||
pub fn reader_to_file(mut reader io.BufferedReader, length int, path string) ! {
|
||||
mut file := os.create(path)!
|
||||
defer {
|
||||
file.close()
|
||||
}
|
||||
|
|
@ -69,11 +69,11 @@ pub fn match_array_in_array<T>(a1 []T, a2 []T) int {
|
|||
|
||||
// read_until_separator consumes an io.Reader until it encounters some
|
||||
// separator array. The data read is stored inside the provided res array.
|
||||
pub fn read_until_separator(mut reader io.Reader, mut res []u8, sep []u8) ? {
|
||||
pub fn read_until_separator(mut reader io.Reader, mut res []u8, sep []u8) ! {
|
||||
mut buf := []u8{len: sep.len}
|
||||
|
||||
for {
|
||||
c := reader.read(mut buf)?
|
||||
c := reader.read(mut buf)!
|
||||
res << buf[..c]
|
||||
|
||||
match_len := match_array_in_array(buf[..c], sep)
|
||||
|
|
@ -84,7 +84,7 @@ pub fn read_until_separator(mut reader io.Reader, mut res []u8, sep []u8) ? {
|
|||
|
||||
if match_len > 0 {
|
||||
match_left := sep.len - match_len
|
||||
c2 := reader.read(mut buf[..match_left])?
|
||||
c2 := reader.read(mut buf[..match_left])!
|
||||
res << buf[..c2]
|
||||
|
||||
if buf[..c2] == sep[match_len..] {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ pub fn exit_with_message(code int, msg string) {
|
|||
}
|
||||
|
||||
// hash_file returns the sha256 hash of a given file
|
||||
pub fn hash_file(path &string) ?string {
|
||||
pub fn hash_file(path &string) !string {
|
||||
file := os.open(path) or { return error('Failed to open file.') }
|
||||
|
||||
mut sha256sum := sha256.new()
|
||||
|
|
@ -39,7 +39,7 @@ pub fn hash_file(path &string) ?string {
|
|||
|
||||
// This function never actually fails, but returns an option to follow
|
||||
// the Writer interface.
|
||||
sha256sum.write(buf[..bytes_read])?
|
||||
sha256sum.write(buf[..bytes_read])!
|
||||
}
|
||||
|
||||
return sha256sum.checksum().hex()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue