Item1441: No way to open a handle on an attachment from Func

Priority: Enhancement
Current State: Closed
Released In: 1.1.0
Target Release: minor
Applies To: Engine
Reported By: CrawfordCurrie
Waiting For:
Last Change By: KennethLavrsen
This can be very important when you are working with very large attachments, where reading the entire attachment is just stupid. Two types of open are require, open-read and open-write (optional append). Solution:

openAttachment($web, $topic, $attachment, $mode) -> $fh

Opens the given attachment. The attachment must exist. The attachment will be locked for other changes as long as the file handle is open. Modes '>', '<' and '>>' should be supported.

Errors will be signalled by an Error::Simple exception.


testAttachment(web, topic, attachment, mode)

Performs a type test on the given attachment.
  • $test - the test to perform
  • $web, $topic $attachment
The return value is the value that would be returned by the standard perl file operations, as indicated by $type
  • r File is readable by current user (tests Foswiki permissions, not file permissions)
  • w File is writable by current user (tests Foswiki permissions, not file permissions)
  • e File exists.
  • z File has zero size.
  • s File has nonzero size (returns size).
  • T File is an ASCII text file (heuristic guess).
  • B File is a "binary" file (opposite of T).
  • M Last modification time (epoch seconds).
  • A Last access time (epoch seconds).
Note that all these types should behave as the equivalent standard perl operator behaves, except M and A which are independent of the script start time (see perldoc -f -X for more information)

See WhatTheFunc
Ended up adding openAttachment and testAttachment to Foswiki::Meta but not Foswiki::Func. Meta is published, and the function site better there anyway. Persuaded by Sven to use a mode parameter rather than having two functions.

-- CrawfordCurrie - 15 Apr 2009

ItemTemplate edit

Summary No way to open a handle on an attachment from Func
ReportedBy CrawfordCurrie
SVN Range SVN 3415: Foswiki-1.1.0-dev, Sun, 05 Apr 2009, build 3374
AppliesTo Engine
Priority Enhancement
CurrentState Closed
Checkins distro:9779dbf5247b distro:6fc0ed4015f8 distro:bdb52020347d
TargetRelease minor
ReleasedIn 1.1.0
Topic revision: r9 - 04 Oct 2010, KennethLavrsen - This page was cached on 15 Jan 2018 - 08:54.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License