From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 4A33825243 for ; Sun, 14 Jan 2024 23:10:15 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1705270215; b=sUzNd8NAQbcn2LFiSiFf0uJleJUYTw6zc+CzgOEnHO4UtPjj35kE+dn6a2QVPhuOpLGe1bU+TX 4oacjKGP61rYdSXLgt3Bvpnn0yAPxZ0ZgIQHgOFWerwewREdvy3j7Dk42Qpdaf9H4rCa8LluMa 8cjmY5+a5EhLtXDIvD063KrruimnTq4gVjRgL0ivX69uqUXA7jVduWK8FIAWuRKvLsAhW8KevN 95bKnMTr7XczKFlWlFey+J54JzYRzpixU+tCoalWEDQ+NCrXaus7ESMZEdQ1Qhg+P0tbUh4SUf 8ju5y2qi03plCAOIClCnrduYdz6bUSa/lXJZBXB7XpBhfw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f53.google.com) smtp.remote-ip=209.85.218.53; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1705270215; bh=lBobozEVMIQ5jiQc7mihe1q0rJv0qLm1GoAPJE5TQgI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=I3koQU0tKYkHmE9uTrW8VLGNvc9i6M1Nx/NIiDZ/BkGYykyeCxL9fYot/FkSu6voKuTkF6z8mJ g4cB7cP6EITgRKebNi77BKJ5f3bOmfpRgKJcw+1kq16MzNDLSJEZJkaG6F6TMQsNbDOQiHOSYD WFhRfUpZqEqutg6C8a7Y/coItODl17mhNaEuaJD3NJALP0o2leVHdSJZbh166JmpLhf2ZVJL6i F06jZznBwYIVbnyFskPci0qiTd3IYoVK66eSaC+wfzQuDck+eeKxzHI87ot3vMykGdrOp3KgFN cea6+bv0aofUnX1ktE61N7ojSgdAjJySDMRlX8uDqDKQ6g==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=ksByVNOCxZ7v8yAGsuYMQgE+x+X1IRyGZAcLVRGHbVY=; b=f43U92rlLW8YAx3thCRKG4THNe 4UE4dI1U/8iu7//r86B8rWveXMpYQPr4byyLuzaM3KSndOrlwRlAc37rZ4rE6jWtiMXAmWvWJ5L2Q YVD80sBke6ypjqpwB0HyweUq4hzYC4D3i0NrFXDYyPRqTktenk1SZmPwt/pM58ipE7VKD9ejQ8E4E AQyky4+KwWVEUUZjRMbDlfpgj6c7bhnslxvhaK7LHYHcF90Sty/7ZNSc6u5PKefeo62EW807oWhOF +3eg4ZHDHoBLyJNCItjZDsdSbBkWsdzrCkksXXTQKGigQrBg17VEbWaeSaxnalSt6x92Whbus8i6N LNGfxeDQ==; Received: by zero.zsh.org with local id 1rP8gJ-000IZh-My; Sun, 14 Jan 2024 22:10:15 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f53.google.com) smtp.remote-ip=209.85.218.53; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f53.google.com ([209.85.218.53]:59453) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rP8fY-000HtN-EQ; Sun, 14 Jan 2024 22:09:29 +0000 Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a28b1095064so905760066b.2 for ; Sun, 14 Jan 2024 14:09:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1705270167; x=1705874967; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ksByVNOCxZ7v8yAGsuYMQgE+x+X1IRyGZAcLVRGHbVY=; b=c13Fktu085rpkfbtoSMHqudIQrPgDLvQJijcgM/aSu9L7xQk9iXe/85O3BCb0bENPC OOAHcJUH0ocKXMY82tMSS6Z+MaggiyS9GyPwDpBQKpUUCPejJzsalctpRYBmbaQivk8k 5uB3InbXijCEMN+p1ksm40jVul1m/2hk64rzhFt6GxUMra4Ae9BoRd69N5RfiGMt83YM fF7BHE8oPdsLggcXe41HU1ItzWIVJPP9qeuLvY7QX8afXGy2YWq8511cFiFYLhIhF0vj m4w3p+mwLeTEJUxzStMZGtmPrW/nHJnqalztorvHSTJACMYymFM7tby1rjiaZH7lz7Bs h5yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705270167; x=1705874967; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ksByVNOCxZ7v8yAGsuYMQgE+x+X1IRyGZAcLVRGHbVY=; b=VO2EVe3J93LxK998NFFnNtTiItXJ1SuoZYfC/ZvcLWraUT5/o1ksNSxO80YYgUHin3 fOey3C7TLPtKqdmygkFeBJNesOgGGNxZxyDUp8ES+K5q+z0xsV/P7LJQ+5/e8ak1HZiy DMOc76TVwWpZEHV2V4U1ftnbrsOdlqelecWIsnasjvQ/+AXXseoWW+tbg44y1v9NtTvz mTvVkOWGvOFOcLqr12azTivT+U8XSBhSvlUoP8xaiLACAOmM7cO/88LDVVS9CFONMIxk OwK/UByMUxlggjz/JFRVENvy1IiBRWWLOVkDV+OVFW2Zq3qFP2tjdxkJFqfJ2O3LBYMS adzg== X-Gm-Message-State: AOJu0Yxi0v9+EzjWqQKi+Wqj+KcAr8HZcVDUDC5sYKnyKH1+pbyuanHE VPYbXEukQoD/0PXBExMQ+cmTaCLdWiqSfQPOfYKnlXu1AK54m7WRjJKPxdqUdQ== X-Google-Smtp-Source: AGHT+IHtrIlZe3yCxIo9bo1a6Cx2JkgMgquMKhZ++de8jACFusLxRZzjrHPEHl2ru9f2WfTs3BiE2C3AVbCKoPcotfo= X-Received: by 2002:a17:907:a0cf:b0:a2c:e169:7565 with SMTP id hw15-20020a170907a0cf00b00a2ce1697565mr819229ejc.123.1705270167492; Sun, 14 Jan 2024 14:09:27 -0800 (PST) MIME-Version: 1.0 References: <205735b2-11e1-4b5e-baa2-7418753f591f@eastlink.ca> In-Reply-To: From: Bart Schaefer Date: Sun, 14 Jan 2024 14:09:16 -0800 Message-ID: Subject: Re: Slurping a file (was: more spllitting travails) To: Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 29477 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Sun, Jan 14, 2024 at 2:34=E2=80=AFAM Roman Perepelitsa wrote: > > On Sat, Jan 13, 2024 at 9:02=E2=80=AFPM Bart Schaefer wrote: > > > > IFS=3D read -rd '' file_content > In addition to being unable to read files with nul bytes, this > solution suffers from additional drawbacks: > > - It's impossible to distinguish EOF from I/O error. Pretty sure you can do that by examining $ERRNO on nonzero status? > - It's slow when reading from non-file file descriptors. > - It's slower than the optimized sysread-based slurp (see below) for > larger files. I'm curious whether setopt nomultibyte read -u 0 -k 8192 ... is actually that much slower in a slurp-like loop. > Here's a version with linear time complexity: > > function slurp() { > emulate -L zsh -o no_multibyte > zmodload zsh/system || return > local -a content > local -i i > while true; do > sysread 'content[++i]' && continue Another thought: Use -c count option to get number of bytes read and -s $size option to specify buffer size. If (( $count =3D=3D $size )) then double $size for the next read. > (( $? =3D=3D 5 )) || return > break > done > typeset -g REPLY=3D${(j::)content} Why the typeset here? Just assign? > }