lib/hexapdf/cli/command.rb in hexapdf-0.16.0 vs lib/hexapdf/cli/command.rb in hexapdf-0.17.0

- old
+ new

@@ -2,11 +2,11 @@ # #-- # This file is part of HexaPDF. # # HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby -# Copyright (C) 2014-2020 Thomas Leitner +# Copyright (C) 2014-2021 Thomas Leitner # # HexaPDF is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License version 3 as # published by the Free Software Foundation with the addition of the # following permission added to Section 15 as permitted in Section 7(a): @@ -349,9 +349,18 @@ doc.each(only_current: false) do |obj| next unless obj.kind_of?(HexaPDF::Dictionary) if (obj.type == :Pages || obj.type == :Page) && !retained.key?(obj.data) doc.delete(obj) end + end + end + + # Returns the human readable file size. + def human_readable_file_size(size) + case size + when 0..9999 then "#{size}B" + when 10_000..999_999 then "#{(size / 1024.to_f).round(1)}K" + else "#{(size.to_f / 1024 / 1024).round(1)}M" end end private