Perhaps it is important to distinguish between literary works and reference works. People keep saying authors write because "there's a book inside them that needs to come out" and compare them to musicians. I think this only holds for the "literary" kind.
And perhaps the "reference" kind has been obsoleted by the internet. Does anyone still turn to their paper encyclopedia instead of to Google/Wikipedia? Do you still buy
Some types of non-fiction, such as text books, may still be read cover-to-cover. But even there it's usually only the "introductionary" types; from many "advanced" books you usually only need specific information. If the necessary chapter happens to be readable online, there's really no need to buy the rest of the book.
Maybe I'll write an "Advanced Computer Programming" book next to my introductionary one
, and see which one sells best and/or gets pirated the most...