xxoo/node-fswin

Support FILE_ATTRIBUTE_SPARSE_FILE

Closed this issue · 3 comments

There's a lot of use for having sparse files enabled on Windows, which doesn't seem to be possible in node's regular FS API.

Specifically, the FILE_ATTRIBUTE_SPARSE_FILE attribute toggles this.

Specifically, this would be useful for random-access-file which is often used for storing large sparse files.

Would a PR that adds this attribute to setAttributes.h be welcome?

xxoo commented

Sure. I'd like to have more useful api implanted. And adding it to setAttributes might be the best way for user (compare to a new api). Please send your pr, thanks!

xori commented

Writing some notes for myself/the implementer.

You cannot create a sparse file by calling CreateFile with FILE_ATTRIBUTE_SPARSE_FILE in the dwFlagsAndAttributes parameter. You must use the FSCTL_SET_SPARSE control code. [via the DeviceIoControl function] Example Invocation

The only way to clear this attribute [set as not sparse] is to overwrite the file (for example, by calling the CreateFile function with the CREATE_ALWAYS flag).

You can determine whether there are any sparse regions in a file by using the FSCTL_QUERY_ALLOCATED_RANGES control code. Example Invocation

Currently don't have bandwidth or an urgent need to work on this since priorities got shifted from when I investigated before. Would be down to help folks figure it out if they have time though.