From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: [HELP] (bug?) Saving a buffer without any conversion? Date: 15 Jan 2003 12:02:40 +0100 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <5xk7h67k1b.fsf@kfs2.cua.dk> References: <87fzrxszs8.fsf@lexx.delysid.org> <200301150116.KAA09223@etlken.m17n.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1042624974 8965 80.91.224.249 (15 Jan 2003 10:02:54 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 15 Jan 2003 10:02:54 +0000 (UTC) Cc: emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18YkNp-0002KS-00 for ; Wed, 15 Jan 2003 11:02:53 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18YkWD-0000tT-00 for ; Wed, 15 Jan 2003 11:11:33 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18YkP3-0003l4-02 for emacs-devel@quimby.gnus.org; Wed, 15 Jan 2003 05:04:09 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18YkOU-0003Oe-00 for emacs-devel@gnu.org; Wed, 15 Jan 2003 05:03:34 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18YkOE-0002Zo-00 for emacs-devel@gnu.org; Wed, 15 Jan 2003 05:03:24 -0500 Original-Received: from mail.filanet.dk ([195.215.206.179]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18YkOC-0002To-00 for emacs-devel@gnu.org; Wed, 15 Jan 2003 05:03:16 -0500 Original-Received: from kfs2.cua.dk.cua.dk (kfs2.local.filanet.dk [192.168.1.182]) by mail.filanet.dk (Postfix) with SMTP id EEE647C012; Wed, 15 Jan 2003 11:03:14 +0100 (CET) Original-To: Kenichi Handa In-Reply-To: <200301150116.KAA09223@etlken.m17n.org> Original-Lines: 109 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 Original-cc: mlang@delysid.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:10741 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:10741 Kenichi Handa writes: > In article <87fzrxszs8.fsf@lexx.delysid.org>, Mario Lang writes: > > We're receiving binary content via a network process. After the > > transfer is complete, this buffer should be saved to a file. > > > The effect I'm having is that we receive 1372422 bytes via the process > > filter function STRING argument, and after insertion into a buffer, > > we have a buffer with buffer-size 1372422, but after calling (save-buffer) > > we get this: > > > -rw-r--r-- 1 root root 1865264 Jan 13 18:35 blah28.mp3 > > > I'm using: > > > (set-process-coding-system proc 'binary 'binary) > > (set-buffer-file-coding-system 'no-conversion t) > > storm@cua.dk (Kim F. Storm) writes: > > I have looked at Mario's data before sending it to emacs and after > > emacs has written it to a file. > > > It seems that every byte in the range 0xa0 .. 0xff that were in the > > original file is prefixed with an 0x81 byte in the file containing the > > received data. To me, that looks like the internal multi-byte > > representation for the binary data. > > No. 0x81 means that 0xA0..0xFF are decoded as Latin-1 > chars. That's why raw-text and no-conversion write out 0x81 > as is to a file. And that means that somehow: > (set-process-coding-system proc 'binary 'binary) > didn't take effect. When did you execute this function? It > should be before accepting any data from the process > (usually just after start-process or open-network-stream). > Mario's code is using open-network-stream, and the set-process-... things are done immediately after creating the process (IIRC). He uses a process filter to "insert" the received strings to the buffer like this [approximately]: (defun filter (proc string) (with-current-buffer (process-buffer proc) (insert string))) Here is a small, selfcontained test case. If you eval the following form, wait a few seconds, the result is "BUFFER=10 FILE=20" meaning that the temp.out buffer is 10 "bytes", but the written file is 20 "bytes". Adding the "set-buffer-multibyte" line produces the right result. (let (proc proc2) (if (get-buffer "temp.out") (kill-buffer "temp.out")) (save-excursion (set-buffer (get-buffer-create "temp.out")) (set-buffer-file-coding-system 'binary) (erase-buffer) ;; (set-buffer-multibyte nil) ) (setq proc (make-network-process :server t :name "temp" :buffer "temp.out" :service 2000 :sentinel nil :filter (lambda (proc string) (with-current-buffer (get-buffer "temp.out") (insert string))) :coding 'binary)) (setq proc2 (make-network-process :name "temp2" :buffer nil :service 2000 :host 'local :coding 'binary)) (sleep-for 1) (process-send-string proc2 (make-string 10 255)) (sleep-for 1) (delete-process proc2) (save-excursion (set-buffer (get-buffer "temp.out")) (let (require-final-newline) (delete-file "/tmp/temp.out") (write-file "/tmp/temp.out"))) (sleep-for 1) (delete-process proc) (format "BUFFER=%d FILE=%d" (buffer-size (get-buffer "temp.out")) (nth 7 (file-attributes "/tmp/temp.out"))) ) -- Kim F. Storm http://www.cua.dk