Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can pack bytes into a structure in prolog succintly enough too

   open('test.tar',read,TarFile)
   HSizes = [100,8,8,8,12,12,8,1,100,6,2,32,32,8,8,155,12],
   maplist(length,HBytes,HSizes),
   append(HBytes,~read_bytes(TarFile,512)),
HBytes is now a list of lists of your bytes, do with them as you please, we can even name them if we want

  HFields = [ filename, filemode, ownerid, groupid, filesize
            , modificationtime, checksum, typeflag, linkedfilename
            , ownerusername, ownergroupname, devicemajornumber
            , deviceminornumber, filenameprefix, padding],
  keys_and_values(HFields,HBytes,Header), 
you could push it off into a predicate and it'd even more or less work relationally and it'd probably be faster than the DCG...

but it wouldn't be interesting.

And like they said https://news.ycombinator.com/item?id=34431450



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: