[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question: estimating size of a buffer when written to file?
From: |
Daniel Martín |
Subject: |
Re: Question: estimating size of a buffer when written to file? |
Date: |
Wed, 08 Dec 2021 17:29:46 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin) |
Stephen Berman <stephen.berman@gmx.net> writes:
> On Wed, 8 Dec 2021 15:55:42 +0000 Qiantan Hong <qhong@mit.edu> wrote:
>
>>> Is (string-bytes (buffer-string)) not reliable?
>>>
>>> Steve Berman
>> I’m not very familiar with different kinds of encoding,
>> but would some coding system result in final
>> writes longer than internal string-bytes?
>
> I'm afraid I don't know either.
>
Yes, if the coding system is not the UTF-8 variant used by Emacs
internally, the result won't be accurate for some scripts. You need to
encode the contents of the buffer/string using the value of
buffer-file-coding-system, for example, and call string-bytes on it.