/// /** * Marks the beginning of a group of values prefixed by a type encoding string. */ export declare class BeginTypedValues { encodings: Array; constructor(encodings: Array); } /** * Marks the end of a group of values prefixed by a type encoding string. * * This event is provided for convenience and doesn't correspond to any data in the typedstream. */ export declare class EndTypedValues { } /** * A reference to a previously read object. */ export declare class ObjectReference { referencedType: ObjectReference.Type; number: number; constructor(referencedType: ObjectReference.Type, number: number); } export declare namespace ObjectReference { /** * Describes what type of object a reference refers to. */ enum Type { C_STRING = "C string", CLASS = "class", OBJECT = "object" } } /** * A NeXTSTEP atom (NXAtom), i. e. a shared/deduplicated C string. * * In (Objective-)C on NeXTSTEP, * atoms are immutable C strings that have been deduplicated so that two atoms with the same content always have the same address. * This allows checking two atoms for equality by just comparing the pointers/addresses, * instead of having to compare their contents. * Other than that, * atoms behave like regular C strings. * * Mac OS X/macOS no longer supports atoms and throws an exception when attempting to decode them using ``NSUnarchiver``. * * This is a thin wrapper around a plain :class:`bytes` object. * The wrapper class is used to distinguish atoms from untyped bytes. */ export declare class Atom { contents?: Buffer; constructor(contents?: Buffer); } /** * An Objective-C selector. * * This is a thin wrapper around a plain :class:`bytes` object. * The wrapper class is used to distinguish selector values from untyped bytes. */ export declare class Selector { name?: Buffer; constructor(name?: Buffer); } /** * Information about a C string as it is stored in a typedstream. * * This is a thin wrapper around a plain :class:`bytes` object. * The wrapper class is used to distinguish typed C string values from untyped bytes. */ export declare class CString { contents: Buffer; constructor(contents: Buffer); } /** * Information about a class (name and version), * stored literally in a chain of superclasses in a typedstream. * * A class in a typedstream can be stored literally, as a reference, or be ``Nil``. * A literally stored class is always followed by information about its superclass. * If the superclass information is also stored literally, * it is again followed by information about its superclass. * This chain continues until a class is reached that has been stored before * (in which case it is stored as a reference) * or a root class is reached * (in which case the superclass is ``Nil``). * * The beginning and end of such a chain of superclasses are not marked explicitly in a typedstream, * and no events are generated when a superclass chain begins or ends. * A superclass chain begins implicitly when a literally stored class is encountered * (if no chain is already in progress), * and the chain ends after the first non-literal (i. e. reference or ``Nil``) class. */ export declare class SingleClass { name: string; version: number; constructor(name: string, version: number); } /** * Marks the beginning of a literally stored object. * * This event is followed by information about the object's class, * stored as a chain of class information (see :class:`SingleClass`). * This class chain is followed by an arbitrary number of type-prefixed value groups, * which represent the object's contents. * The object ends when an :class:`EndObject` is encountered where the next value group would start. */ export declare class BeginObject { } /** * Marks the end of a literally stored object. */ export declare class EndObject { } /** * Represents an array of bytes (signed or unsigned char). * * For performance and simplicity, * such arrays are read all at once and represented as a single event, * instead of generating one event per element as for other array element types. */ export declare class ByteArray { elementEncoding: string; data: Buffer; constructor(elementEncoding: string, data: Buffer); } /** * Marks the beginning of an array. * * This event is provided for convenience and doesn't directly correspond to data in the typedstream. * The array length and element type information provided in this event actually comes from the arrays's type encoding. * * This event is followed by the element values, * which are not explicitly type-prefixed, * as they all have the type specified in the array type encoding. * The end of the array is not marked in the typedstream data, * as it can be determined based on the length and element type, * but for convenience, * an :class:`EndArray` element is generated after the last array element. * * This event is *not* generated for arrays of bytes (signed or unsigned char) - * such arrays are represented as single :class:`ByteArray` events instead. */ export declare class BeginArray { elementEncoding: string; length: number; constructor(elementEncoding: string, length: number); } /** * Marks the end of an array. * * This event is provided for convenience and doesn't correspond to any data in the typedstream. */ export declare class EndArray { } /** * Marks the beginning of a struct. * * This event is provided for convenience and doesn't directly correspond to data in the typedstream. * The struct name and field type information provided in this event actually comes from the struct's type encoding. * * This event is followed by the field values, * which are not explicitly type-prefixed (unlike in objects), * as their types are specified in the struct type encoding. * The end of the struct is not marked in the typedstream data, * as it can be determined based on the type information, * but for convenience, * an :class:`EndStruct` element is generated after the last struct field. */ export declare class BeginStruct { name?: string; fieldEncodings: Array; constructor(fieldEncodings: Array, name?: string); } /** * Marks the end of a struct. * * This event is provided for convenience and doesn't correspond to any data in the typedstream. */ export declare class EndStruct { } export declare type ReadEvent = BeginTypedValues | EndTypedValues | number | ObjectReference | CString | Atom | Selector | Buffer | SingleClass | BeginObject | EndObject | ByteArray | BeginArray | EndArray | BeginStruct | EndStruct | undefined; /** * Reads typedstream data from a raw byte stream. */ export declare class TypedStreamReader implements Iterator { private EOF_MESSAGE; private data; private pos; sharedStringTable: Array; streamerVersion: number; byteOrder: "LE" | "BE"; systemVersion: number; private eventsIterator; /** * Create a :class:`TypedStreamReader` that reads data from the given raw byte stream. * * @param data The raw byte stream from which to read the typedstream data. * By default this is ``False`` and callers are expected to close the raw stream themselves after closing the :class:`TypedStreamReader`. */ constructor(data: Buffer); next(): IteratorResult; [Symbol.iterator](): Generator; /** * Read byte_count bytes from the raw stream and raise an exception if too few bytes are read * (i. e. if EOF was hit prematurely). */ private readExact; /** * Read a head byte. * * @param head If ``None``, the head byte is read normally from the stream. * Otherwise, the passed-in head byte is returned and no read is performed. * This parameter is provided to simplify a common pattern in this class's internal methods, * where methods that need to read a head byte * can alternatively accept an already read head byte as a parameter * and skip the read operation. * This mechanism is used to allow a limited form of lookahead for the head byte, * which is needed to parse string and object references and to detect end-of-object markers. * @return The read or passed in head byte. * @private */ private readHeadByte; /** * Read a low-level integer value. * * @param signed Whether to treat the integer as signed or unsigned. * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return The decoded integer value. * @private */ private readInteger; /** * Read a low-level single-precision float value. * * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return The decoded float value * @private */ private readFloat; /** * Read a low-level double-precision float value. * * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return The decoded double value * @private */ private readDouble; /** * Read a low-level string value. * * Strings in typedstreams have no specificed encoding, * so the string data is returned as raw :class:`bytes`. * (In practice, they usually consist of printable ASCII characters.) * * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return The read string data, which may be ``nil``/``None``. * @private */ private readUnsharedString; /** * Read a low-level shared string value. * * A shared string value may either be stored literally (as an unshared string) * or as a reference to a previous literally stored shared string. * Literal shared strings are appended to the :attr:`shared_string_table` after they are read, * so that they can be referenced by later non-literal shared strings. * This happens transparently to the caller - * in both cases the actual string data is returned. * * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return The read string data, which may be ``nil``/``None``. * @private */ private readSharedString; /** * Read an object reference value. * * Despite the name, * object references can't just refer to objects, * but also to classes or C strings. * The type of object that a reference refers to is always clear from context * and is not explicitly stored in the typedstream. * * @param referencedType The type of object that the reference refers to. * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return The read object reference. * @private */ private readObjectReference; /** * Read a C string value. * * A C string value may either be stored literally * or as a reference to a previous literally stored C string value. * Literal C string values are returned as :class:`CString` objects. * C string values stored as references are returned as :class:`ObjectReference` objects * and are not automatically dereferenced. * * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return The read C string value or reference, which may be ``nil``/``None``. * @private */ private readCString; /** * Iteratively read a class object from the typedstream. * * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return An iterable of events representing the class object. * See :class:`SingleClass` for information about what events are generated when and what they mean. * @private */ private readClass; /** * Iteratively read an object from the typedstream, * including all of its contents and the end of object marker. * * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return An iterable of events representing the object. * See :class:`BeginObject` and :class:`EndObject` for information about what events are generated when and what they mean. * @private */ private readObject; /** * Iteratively read a single value with the type indicated by the given type encoding. * * The type encoding string must contain exactly one type * (although it may be a compound type like a struct or array). * Type encoding strings that might contain more than one value must first be split using :func:`_split_encodings`. * * @param typeEncoding * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @return An iterable of events representing the object. * Simple values are represented by single events, * but more complex values (classes, objects, arrays, structs) usually generate multiple events. * @private */ private readValueWithEncoding; /** * Iteratively read the next group of typed values from the stream. * * The type encoding string is decoded to determine the type of the following values. * * @param head An already read head byte to use, or ``None`` if the head byte should be read from the stream. * @param endOfStreamOk Whether reaching the end of the data stream is an acceptable condition. * If this method is called when the end of the stream is reached, * an :class:`EOFError` is raised if this parameter is true, * and an :class:`InvalidTypedStreamError` is raised if it is false. * If the end of the stream is reached in the middle of reading a value * (not right at the beginning), * the exception is always an :class:`InvalidTypedStreamError`, * regardless of the value of this parameter. * @return An iterable of events representing the typed values. * See :class:`BeginTypedValues` and :class:`EndTypedValues` for information about what events are generated when and what they mean. */ private readTypedValues; /** * Iteratively read all values in the typedstream. * * @return An iterable of events representing the contents of the typedstream. * Top-level values in a typedstream are always prefixed with a type encoding. * See :class:`BeginTypedValues` and :class:`EndTypedValues` for information about what events are generated when and what they mean. * @private */ private readAllValues; }