Created
August 2, 2024 05:26
-
-
Save kmahyyg/537a503be7a4aaa9c85cbbbd2f4ee4e8 to your computer and use it in GitHub Desktop.
NSON JSON Converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"compress/flate" | |
"flag" | |
"io" | |
"log" | |
"os" | |
"strings" | |
) | |
func main() { | |
// Define command line flags | |
input := flag.String("i", "", "Input file path") | |
output := flag.String("o", "", "Output file path") | |
flag.Parse() | |
// Check if input and output are provided | |
if *input == "" || *output == "" { | |
log.Println("Input and output file paths are required") | |
os.Exit(1) | |
} | |
// Determine mode based on the file extension | |
mode := "compress" | |
if strings.HasSuffix(*input, ".nson") { | |
mode = "decompress" | |
} | |
// Open input file | |
inputFile, err := os.Open(*input) | |
if err != nil { | |
log.Printf("Failed to open input file: %s\n", err) | |
os.Exit(1) | |
} | |
defer inputFile.Close() | |
// Create output file | |
outputFile, err := os.Create(*output) | |
if err != nil { | |
log.Printf("Failed to create output file: %s\n", err) | |
os.Exit(1) | |
} | |
defer outputFile.Close() | |
// Set up flate writer or reader | |
var stream io.ReadCloser | |
var w io.WriteCloser | |
if mode == "compress" { | |
w, err = flate.NewWriter(outputFile, flate.DefaultCompression) | |
if err != nil { | |
log.Printf("Failed to create flate writer: %s\n", err) | |
os.Exit(1) | |
} | |
defer w.Close() | |
} else { | |
stream = flate.NewReader(inputFile) | |
defer stream.Close() | |
} | |
// Perform the compression or decompression | |
if mode == "compress" { | |
_, err = io.Copy(w, inputFile) | |
} else { | |
_, err = io.Copy(outputFile, stream) | |
} | |
if err != nil { | |
log.Printf("Failed to process data: %s\n", err) | |
os.Exit(1) | |
} | |
log.Println("Operation completed successfully.") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is used to convert NaniNovel game save from NSON format to JSON format and verse vesa.
Can be compiled on
go version go1.22.4