Class Narc

java.lang.Object
io.github.turtleisaac.nds4j.Narc

public class Narc extends Object
  • Field Details

  • Constructor Details

    • Narc

      public Narc()
    • Narc

      public Narc(byte[] data)
      Read NARC data, and create a filename table and a list of files.
      Parameters:
      data - a byte[] representation of a Narc
  • Method Details

    • fromFile

      public static Narc fromFile(String file)
      Load a NARC archive from a filesystem file
      Parameters:
      file - a String containing the path to a NARC file on disk
      Returns:
      a Narc object
    • fromFile

      public static Narc fromFile(File file)
      Load a NARC archive from a file on disk
      Parameters:
      file - a File object representing the path to a NARC file on disk
      Returns:
      a Narc object
    • fromUnpacked

      public static Narc fromUnpacked(String dir, boolean removeFilenames, Endianness endiannessOfBeginning)
      Load an unpacked NARC from a directory on disk
      Parameters:
      dir - a String object containing the path to an unpacked NARC directory on disk
      removeFilenames - whether the NARC should have a Fnt (ignored if there are subfolders within)
      endiannessOfBeginning - whether the NARC's beginning is encoded in Big Endian or Little Endian - can be Endianness.BIG or Endianness.LITTLE
      Returns:
      a Narc object
    • fromUnpacked

      public static Narc fromUnpacked(File dir, boolean removeFilenames, Endianness endiannessOfBeginning)
      Load an unpacked NARC from a directory on disk
      Parameters:
      dir - a File object representing the path to an unpacked NARC directory on disk
      removeFilenames - whether the NARC should have a Fnt (ignored if there are subfolders within)
      endiannessOfBeginning - whether the NARC's beginning is encoded in Big Endian or Little Endian - can be Endianness.BIG or Endianness.LITTLE
      Returns:
      a Narc object
      Throws:
      RuntimeException - if the specified path on disk does not exist or is not a directory
    • fromContentsAndNames

      public static Narc fromContentsAndNames(ArrayList<byte[]> files, Fnt.Folder filenames, Endianness endiannessOfBeginning)
      Create a NARC archive from a list of files and (optionally) a filename table.
      Parameters:
      files - an ArrayList of byte[]'s representing all the subfiles in the NARC
      filenames - an (OPTIONAL) Folder representing the NARC's filesystem
      endiannessOfBeginning - whether the NARC's beginning is encoded in Big Endian or Little Endian - can be Endianness.BIG or Endianness.LITTLE
      Returns:
      a Narc representation of the provided parameters
    • unpack

      public void unpack(String dir) throws IOException
      Unpacks this Narc to disk at the specified path
      Parameters:
      dir - a String containing the target directory to unpack the NARC to
      Throws:
      RuntimeException - if this Narc has an internal filesystem, the specified path already exists, a new directory at the specified path could not be created, or a failure to write the subfiles occurred
      IOException - if the parent directory of the output subfiles does not exist
    • unpack

      public void unpack(File dir) throws IOException
      Unpacks this Narc to disk at the specified path
      Parameters:
      dir - a File containing the target directory to unpack the NARC to
      Throws:
      RuntimeException - if this Narc has an internal filesystem, the specified path already exists, a new directory at the specified path could not be created, or a failure to write the subfiles occurred
      IOException - if the parent directory of the output subfiles does not exist
    • save

      public byte[] save()
      Generate a byte[] representing this NARC.
      Returns:
      a byte[]
    • saveToFile

      public void saveToFile(String path) throws IOException
      Generate a byte[] representing this NARC, and save it to a file on disk
      Parameters:
      path - a String containing the path to the file on disk to save as
      Throws:
      IOException - if the specified file's parent directory does not exist.
    • saveToFile

      public void saveToFile(File file) throws IOException
      Generate a byte[] representing this NARC, and save it to a file on disk
      Parameters:
      file - a File representing the path to the file on disk to save as
      Throws:
      RuntimeException - if the provided path leads to a directory
      IOException - if the specified file's parent directory does not exist.
    • getFileByName

      public byte[] getFileByName(String filename)
      Return the contents of the file with the given filename (path).
      Parameters:
      filename - a String containing the path to the requested NARC subfile
      Returns:
      a byte[] containing the contents of the requested NARC subfile
      Throws:
      RuntimeException - if file with given name is not found
    • setFileByName

      public void setFileByName(String filename, byte[] data)
      Replace the contents of the NARC subfile with the given filename (path) with the given data.
      Parameters:
      filename - a String containing the path to the specified NARC subfile
      data - a byte[] containing the contents to set for the specified NARC subfile
      Throws:
      RuntimeException - if file with given name is not found
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object