nsZip - NSP compressor/decompressor to reduce storage

nsZip is an open source PC tool to lossless compress/decompress NSP files in order to save a lot of storage while all NCA files keep their exact same hash. [prebreak]1[/prebreak]
But it’s more than just a compression. A lot of data like NDV0 partitions or fragment NCA3 files will be removed while compressing and exactly recreated when decompressed which saves even more space especially on updates higher than v65536.
In addition, the NSZ format was designed with emulators in mind so adding NSZ support to Yuzu will be possible in the future and because NSZ contains decrypted NCAs no keys would be needed to only extract game files. As compression algorithm Zstandard is used to multithreaded compress 256 KB chunks while uncompressible chunks are stored uncompressed. That way NSPZ/XCIZ allows random read access. Zstandard has a 43MB/s compression and 7032MB/s decompression speed on an 8 threaded CPU at level 18 while having one of the best compression ratios compared to other compression algorithms.

How compressing works: NSP => extracted NSP => decrypted NCAs => trim fragments => compressing to NSZ => verify correctness => repacking NSPZ file
How decompressing works: NSPZ file => extracted NSPZ => decompress NSZ => untrim fragments => encrypt NCAs => verify correctness => repack as NSP

Check out my GitHub page to report bugs, follow this project, post your suggestions or contribute.
GitHub link: https://github.com/nicoboss/nsZip/releases

For the new homebrew compatible NSZ format please see https://github.com/nicoboss/nsz
NSZ thread: https://gbatemp.net/threads/nsz-homebrew-compatible-nsp-xci-compressor-decompressor.550556/
Until NSZ support is implemented in nsZip I don't see why you want to use it instead of NSZ

Block compressed NSZ is very similar to the beautiful NSPZ format just without all the unnecessarily complexity which made NSPZ unfeasible for other software to implement. I might remove NSPZ/XCIZ support in the future if I see that there's no point in keeping it to not confuse people.

Differences between NSZ and NSPZ:

NSPZ/XCIZ:
- GitHub Project: https://github.com/nicoboss/nsZip
- Always uses Block compression allowing random read access to play compressed games in the future
- Decrypts the whole NCA
- Trims NDV0 fragments to their header and reconstructs them
- Only supported by nsZip and unfortunately doesn't really have a future

NSZ/XCZ:
- GitHub Project: https://github.com/nicoboss/nsz
- Uses solid compression by default. Block compression can be enabled using the -B option. Block compression will be the default for XCZ
- Decrypts all sections while keeping the first 0x4000 bytes encrypted. Puts informations needed to encrypt inside the header.
- Deleted NDV0 fragments as they have no use for end users as they only exist to save CDN bandwidth
- Already widely used. Supported by Tinfoil, SX Installer v3.0.0 and probably a lot of other software in the future


nsZip v2.0.0 preview 2:
  • Fixed XCI to XCIZ compression
nsZip v2.0.0 preview 1:
  • New UI made using WPF instead of WinForms
  • Huge performance improvements
    • Directly decrypt the NSP without extracting it first
    • Directly decompressing NSPZ files without extracting them first
    • Huge encrypting speed increase
    • Huge SHA-256 verification speed increase
    • Enhanced compressing multithreading
    • Support for up to 400 CPU Cores
  • Improved game compatibility
  • Command Line support
  • More settings
Version 1.1.0 Changelog:
  • Added support for over multiple NCAs splitted NDV0 fragment trimming
Version 1.0.1 Changelog:
  • Let the user continue when detecting a yet unimplemented multifile NDV0 fragment. I'll add proper support for that unimplemented multifile NDV0 fragment format in the following days.
  • The compression level can now be changed (tradeoff between speed and compression ratio)
  • The block size can now be changed (tradeoff between random access time and compression ratio)
Future planes:
  • NSZ implementation
FAQ:
Q: It prod.keys not found!
A: Dump them using Lockpick and copy them to %userprofile%/.switch/prod.keys
Q: How much storage does this save?
A: It depends on the game. The compressed size is usually around 40-80% of the original size.
Q: What about XCI?
A: Compression to XCIZ is supported, but XCIZ to XCI recreation is still in development.
Q: The program throws an error or seems to behaves not as intended!
A: Open an issue on my GitHub page where you give me exact steps how to reproduce.
Q: Does this compress installed games?
A: Not now but it's planned for the far future.

Screenshot:

nsZip_Screenshot.png
 
Last edited by nicoboss,

nicoboss

Well-Known Member
OP
Member
Joined
Feb 1, 2019
Messages
132
Trophies
0
Age
26
XP
1,196
Country
Switzerland
Tell me exactly which game and version and it will be fixed as soon as possible – probably in the next 24 hours. I obviously was only able to test nsZip with the games I own so there could be some edge cases I missed. My program will always crash if something seems wrong so it’s extremely unlikely to ever get a corrupted NSPZ. Just try another game until it’s fixed.

Edit: Thanks a lot for your bug report. I was able to recreate the issue and will try to fix it tomorrow. There is something wired going on with newer NDV0 files where the header specifies a larger file size then it's physically file size. The NDV0 file is still very undocumented so I will have to do some research. This issue won’t affect any base games or DLCs NSP files.
 
Last edited by nicoboss,

ReikaRin

Well-Known Member
Member
Joined
Mar 21, 2018
Messages
113
Trophies
0
XP
538
Country
Indonesia
Tell me exactly which game and version and it will be fixed as soon as possible – probably in the next 24 hours. I obviously was only able to test nsZip with the games I own so there could be some edge cases I missed. My program will always crash if it seems something is wrong so it’s extremely unlikely to ever get a corrupted NSPZ. Just try another game until it’s fixed.

i got it working with mario kart v589824 (132mb to 79mb), Gear Club 2 v262144 (1 gb to 783 mb)
not working with Smash Bros v262144, rocket league v983040, Diablo 3 v131072, splatoon 2 v1966080, DB fighter z v196608
 
Last edited by ReikaRin,

nicoboss

Well-Known Member
OP
Member
Joined
Feb 1, 2019
Messages
132
Trophies
0
Age
26
XP
1,196
Country
Switzerland
I'm currently compressing a Mario Kart 8 XCI on a 6 core cpu but it is taking a very long time to write all the 27630 blocks.
Is this intended?
Yes, the game is quite large. I'll add an option to lower the compression level to speed up that progress a lot by trade off some compression ratio in the next version. The default compression level of 18 was probably too high as I always tested on a 16 cores 32 thread CPU.
 
Last edited by nicoboss,

Oleboy555

Well-Known Member
Member
Joined
Feb 8, 2017
Messages
907
Trophies
0
Location
Amsterdam
Website
3ds.guide
XP
2,315
Country
Netherlands
Yes, the game is quite large. I'll add an option to lower the compression level to speed up that progress a lot by trade off some compression ratio in the next version. The default compression level of 18 was probably too high as I always tested on a 16 cores 32 thread CPU.
it finally finished after around 30-40 minutes and took the filesize from 7.43 GB (7,985,954,816 bytes) to 5.27 GB (5,667,007,757 bytes)
 

tigersaman

Well-Known Member
Newcomer
Joined
Jul 10, 2018
Messages
78
Trophies
0
Age
31
XP
1,059
Country
Iran
VVVVVV Base Game:
NSP: 80.6 MB
NSPZ: 55.5 MB

Qbics Paint v131072:
NSP: 142 MB
NSPZ: 46.9 MB

Qbics Paint v65536:
NSP: 69.2 MB
NSPZ: 43.8 MB

Qbics Paint Base Game:
NSP: 65.4 MB
NSPZ: 40.1 MB

This is very good. it reminds me of .cso format for psp. thank you.
 

Cyan

GBATemp's lurking knight
Former Staff
Joined
Oct 27, 2002
Messages
23,749
Trophies
4
Age
46
Location
Engine room, learning
XP
15,662
Country
France
ah, you are right, nsp are installed to the console.
I only thought about game direct access like ciso on PSP (and like SXOS with xci). direct xcz reading might be possible.

installing xcz/nsz is probably the next step.
 
  • Like
Reactions: klear

nicoboss

Well-Known Member
OP
Member
Joined
Feb 1, 2019
Messages
132
Trophies
0
Age
26
XP
1,196
Country
Switzerland
I just released nsZip version 1.0.1!
Version 1.0.1 Changelog:
- Let the user continue when detecting a yet unimplemented multifile NDV0 fragment. I'll add proper support for that unimplemented multifile NDV0 fragment format in the following days.
- The compression level can now be changed (tradeoff between speed and compression ratio)
- The block size can now be changed (tradeoff between random access time and compression ratio)

As answer to all the speculation about what's next:
After improving the PC tool even more the next step will probably be Yuzu support and Tinfoil/Goldleaf like XCIZ/NSPZ installing. If the format gets popular, I could imagine TX adding XCIZ support to their XCI-launcher. Way in the future somebody might write a system model for launching compressed installed NSPZ games. Technically all of this would be possible as the format supports random read access and has way faster decompression speed then any SD-Card's read speed - the question is more if somebody will do it which we can't know now.

Linux support? this work under wine?
You can try compiling nsZip using Mono on Linux. However, this isn't officially supported yet and so there might be some compilation errors. Mono builds for Linux/MacOSX are planned for the future.
 
Last edited by nicoboss,
  • Like
Reactions: hippy dave
Joined
Jan 19, 2019
Messages
755
Trophies
0
XP
947
Country
United Kingdom
I just released nsZip version 1.0.1!
Version 1.0.1 Changelog:
- Let the user continue when detecting a yet unimplemented multifile NDV0 fragment. I'll add proper support for that unimplemented multifile NDV0 fragment format in the following days.
- The compression level can now be changed (tradeoff between speed and compression ratio)
- The block size can now be changed (tradeoff between random access time and compression ratio)

As answer to all the speculation about what's next:
After improving the PC tool even more the next step will probably be Yuzu support and Tinfoil/Goldleaf like XCIZ/NSPZ installing. If the format gets popular, I could imagine TX adding XCIZ support to their XCI-launcher. Way in the future somebody might write a system model for launching compressed installed NSPZ games. Technically all of this would be possible as the format supports random read access and has way faster decompression speed then any SD-Card's read speed - the question is more if somebody will do it which we can't.


You can try compiling nsZip using Mono on Linux. However, this isn't officially supported yet and so there might be some compilation errors. Mono builds for Linux/MacOSX are planned for the future.
Ill try it in a vm under wine will post my results
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    The Real Jdbye @ The Real Jdbye: never had one before that, and never had one since