How is the .blend file thumbnail generated?
As has been pointed out blender has a python script to perform that task. While the *nix variations install this along with blender, the OSX and Windows distributions do not include it.

As with the rest of blender this script is available under the GPL license so you can copy part or all of the script and include it in the script you are making. A call to blend_extract_thumb(path) with the path to the file you want a thumbnail of will return an image buffer and resolution for you to use however you want.