I would like to create a "null" rar. I used the command: fsutil file createnew c:\a.rar 1040000. But when I try to add files to this rar I get an error that the rar is damaged.

How can I create a null rar with pre-set size?

link|improve this question
feedback

migrated from stackoverflow.com Aug 20 '11 at 15:55

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 1 down vote accepted

What do you mean with null rar?

  • A rar file with a certain size where the place for the file is filled with null bytes?
  • The smallest possible rar file that WinRAR can add files too?

When you try to add files to the rar, is this with WinRAR or do you do this yourself programmatically?

Whichever it is, I think you are using the wrong approach for your problem. I also assume you won't be using compression because that is something you can only let WinRAR do.

The first case is only possible when you know the filename beforehand and there is only one file with given size. This is because the rar format contains header blocks that are added before the filename with the file name, CRC info ect. These are things you need to have right if you don't want WinRAR complaining. It is possible to do this with multiple files, beforehand, with null bytes, but you need the actual files to construct it. Then you are just better off doing it right then and there.

For the second case as said on Wikipedia:

The minimum size of a RAR file is 20 bytes.

The following Python code would construct this file. If you open the file in WinRAR, it won't complain. This is the rar Marker block ( MARK_HEAD ) (a magic number) and Archive header ( MAIN_HEAD ). There is no pre-set size: it will grow with each file you add.

>>> with open("minimal.rar", 'w') as rar:
...     rar.write("Rar!\x1a\x07\x00")
...     rar.write("\xF1\xFB\x73\x01\x00\x0D\x00\x00\x00\x00\x00\x00\x00")

I don't understand what you are trying to accomplish, but why don't you just use rar.exe? If you decide to do things yourself, technote.txt is some must read lecture. It is placed in the WinRAR install directory.

If you want some example code, here are some projects that use rar in one way or another:

  • RARFileSource: a DirectShow filter that lets most video players read RAR files on the fly
  • rarfs: Fuse module (Linux) to mount uncompressed RAR archives
  • ReScene: a project for recreating rar archives from the extracted files. You need a .srr file to do this.
  • VLC UnRAR plugin: RAR player for older versions of VLC, now build-in.
  • And then there are also a whole lot of comic book readers that support rars.
  • And for each programming language there is a chance some kind of library exist. Some Python code worth to have a look at: rarfile and pyarrfs.

Edit: Check out this rar tutorial for some command line usage examples.

link|improve this answer
i would like to build a rar that its size is pre-defined and it takes its size from the drive in the moment it is created. after that i want to add file. – Question Jul 13 '11 at 13:07
Do you mean something like this: win-rar.com/index.php?id=24&kb=1&kb_article_id=49 – Gfy Jul 13 '11 at 20:25
feedback

Your Answer

 
or
required, but never shown