Hack Forums
[Source] Vary simple file Pumper in GoLANG - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Source] Vary simple file Pumper in GoLANG (/showthread.php?tid=6166922)



Vary simple file Pumper in GoLANG - SIM-297877 - Aug 6, 2021

Needed a file pumper for a project and wanted to keep using GO so i wrote a simple pumper in go.

Code
package main

import (
    "fmt"
    "log"
    "os"
    "strconv"
)
var (
    FilePath string
    SizeToPump int
)


func main() {
    FilePath = os.Args[1]
    v := os.Args[2]
    i, _ := strconv.Atoi(v)
    SizeToPump = i
    var wantedSize = int64(SizeToPump * 1024 * 1024) //Makes a MB

    fmt.Println("PumpItUp")

    fi, _ := os.Stat(FilePath)

    fmt.Println("Starting Size", fi.Size(), "bytes")

    toPump, err := os.OpenFile(FilePath, os.O_RDWR, 0644)
    if err != nil {
        log.Fatalf("Error Opening File: %s", err)
    }
    defer toPump.Close()

    _, err = toPump.WriteAt([]byte{0}, fi.Size()+wantedSize)
    if err != nil {
        log.Fatalf("Error Writing to File: %s", err)
    }

    fi, _ = os.Stat(FilePath)
    fmt.Println("Pumped Size", fi.Size() / 1024 /1024, "MB")
}

Github: https://github.com/SaturnsVoid/PumpItUp

I have other Go code on my Github and i upload all the time.