From c7ae1a7c23b69a214cebc1c495c9a4b3bf0d35aa Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Fri, 5 Jan 2018 03:22:56 +0000 Subject: [PATCH] A small library to deal with ACiD SAUCE data --- exec/load/sauce_lib.js | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 exec/load/sauce_lib.js diff --git a/exec/load/sauce_lib.js b/exec/load/sauce_lib.js new file mode 100644 index 0000000000..6b350e61f6 --- /dev/null +++ b/exec/load/sauce_lib.js @@ -0,0 +1,87 @@ +// $Id$ +// vi: tabstop=4 + +const defs = { + + datatype: { + none: 0, + character: 1, + bitmap: 2, + vector: 3, + audio: 4, + bintext: 5, + xbin: 6, + archive: 7, + exe: 8, + }, + + filetype: { + ascii: 0, + ansi: 1, + ansimation: 2, + rip: 3, + pcboard: 4, + avatar: 5, + html: 6, + source: 7, + tundra: 8, + }, + + ansiflag: { + nonblink: (1<<0), // high intensity BG, aka iCE colors + spacing_mask: (3<<1), // letter spacing + spacing_legacy: (0<<1), // Legacy value. No preference. + spacing_8pix: (1<<1), // 8-pixel font + spacing_9pix: (2<<1), // 9-pixel font + ratio_mask: (3<<3), // aspect ratio + ratio_legacy: (0<<3), // Legacy value. No preference. + ratio_rect: (1<<3), // Rectangular pixels + ratio_square: (2<<3), // Square pixels + }, + + trailer_length: 128 +}; + +// Pass either a filename or a File instance +function read(fname) +{ + var file; + + if(typeof fname == 'object') + file = fname; + else { + file = new File(fname); + if(!file.open("rb")) + return false; + } + + if(file.length < defs.trailer_length) + return false; + + file.position = file.length - defs.trailer_length; + if(file.read(7) != 'SAUCE00') + return false; + + var obj = {}; + obj.title = file.read(35).trim(); + obj.author = file.read(20).trim(); + obj.group = file.read(20).trim(); + obj.date = file.read(8).trim(); + obj.filesize = file.readBin(4); + obj.datatype = file.readBin(1); + obj.filetype = file.readBin(1); + obj.tinfo1 = file.readBin(2); + obj.tinfo2 = file.readBin(2); + obj.tinfo3 = file.readBin(2); + obj.tinfo4 = file.readBin(2); + obj.comments = file.readBin(1); + obj.tflags = file.readBin(1); + obj.tinfos = truncsp(file.read(22)); + obj.ice_color = function () { + return this.filetype == defs.filetype.ansi && this.tflags&defs.ansiflag.nonblink; + } + return obj; +} + + +this; -- GitLab