--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The (modern) magic file format is rich and well documented. Just `man 5 magic` or google it. If you care about windows users, this approach is not so portable.
Checking a gzip file signature (first two bytes are 1F 8B) with base Racket is pretty easy:(bytes=? (with-input-from-file "some.gz" (λ () (read-bytes 2))) #"\x1F\x8B")
Eric
On Fri, Jun 29, 2018 at 10:13 AM David Storrs <david....@gmail.com> wrote:
On Fri, Jun 29, 2018 at 1:07 PM, Neil Van Dyke <ne...@neilvandyke.org> wrote:David Storrs wrote on 06/29/2018 01:01 PM:
[...]
* Solid: Make a Racket package that parses the `magic` file into
Racket syntax objects, and uses `syntax-parse` to convert those to
Racket code, all at syntax expansion time. This might also be a
demo of Racket's language support, to get a safe and modern
execution of some important legacy code in an obscure language (or
some story like that).
why would it need to be syntax objects?
Sorry, I should've explained my understanding.
Historically, IIRC, at least one version of the `file` program has its logic specified not in C code, but in a file called `magic`, or something like that.
So, perhaps one could "expand" the language of that file into Racket code that is then compiled.
And often one good way to do that in Racket is to parse the input language into something like an abstract syntax tree of Racket syntax objects, and then use `syntax-parse` and/or other programmatic syntax transformation to turn those syntax objects into syntax objects for `racket/base` code that implements the language for that syntax.
Ah, I see. It seems like relying on the 'magic' file represents a weakness and a potential portability issue. My plan had been to have a directory named 'definitions' and fill it with a set of tiny files, each of which exports a hash describing one file format. The main.rkt would read all files in this directory and use their data to interpret whatever file you throw at it. This would allow new file types to be added simply by adding a new file to the 'definitions' directory and everything would Just Work from there. Does this seem like a sensible way to do it?
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe@googlegroups.com.
I'd like to be able to answer the question "Is this file gzipped?" without depending on file extensions, much like the Unix CLI utility 'file'. I've looked through the compression docs (https://docs.racket-lang.org/file/gzip.html and also zip and tar) but been unable to find anything that seems appropriate. There's 'file-creator-and-type' which might work but is Mac specific. There's various things with 'file-type' in the name but they are all inappropriate -- graphics items or etc.
Can someone point me to the right part of the FM?
Tar is a pit