I suggest using resource_size(res) for the length here.