Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse to Read
Browse files Browse the repository at this point in the history
Changes:
- Renamed the `parse` function to `read`! This is more consistent with the Read and Write kind of idea, considering the Parse class is called Reader, instead of Parser. This also simplifies things for when I add JSON support too, with my mixed SNBT-JSON format that I want to create.
- The JSON functions will likely be called `parse` and `stringify`, and the binary NBT functions will be `read` and `write`.
Offroaders123 committed Jun 25, 2022
1 parent 280aabd commit 39b5d85
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import parse from "./parse.js";
import read from "./read.js";
import write from "./write.js";

export { parse, write };
export { read, write };

export default { parse, write, [Symbol.toStringTag]: "NBT" };
export default { read, write, [Symbol.toStringTag]: "NBT" };
10 changes: 5 additions & 5 deletions src/parse.js → src/read.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { tags, types } from "./tags.js";
import { decompress } from "./compression.js";

export default async function parse(data,{ endian } = {}){
export default async function read(data,{ endian } = {}){
if (!data) throw new Error("Unexpected falsy value for the data parameter");

if (typeof endian !== "undefined" && !["big","little"].includes(endian)){
@@ -15,18 +15,18 @@ export default async function parse(data,{ endian } = {}){

if (typeof endian !== "undefined"){
try {
const result = await runParser(data,endian);
const result = await runReader(data,endian);
return result;
} catch (error){
throw error;
}
} else {
let result = null;
try {
result = await runParser(data,"big");
result = await runReader(data,"big");
} catch (error){
try {
result = await runParser(data,"little");
result = await runReader(data,"little");
} catch {
throw error;
}
@@ -35,7 +35,7 @@ export default async function parse(data,{ endian } = {}){
}
}

async function runParser(data,endian){
async function runReader(data,endian){
if (hasGzipHeader(data)) data = await decompress(data,{ encoding: "gzip" });

const reader = new Reader(data,endian);

0 comments on commit 39b5d85

Please sign in to comment.