GithubHelp home page GithubHelp logo

carson-katri / skqueue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from daniel-pedersen/skqueue

1.0 3.0 0.0 26 KB

Monitor changes to files and directories using kernel event notifications (kqueue) in Swift

License: MIT License

Swift 100.00%

skqueue's Introduction

SKQueue

SKQueue is a simple and efficient Swift library that uses kernel event notifications (kernel queues or kqueue) to monitor changes to the filesystem. It allows you to watch any file or folder for changes and be notified immediately when they occur.

Installation

Swift Package Manager

  1. Create a new project ex. swift package init --type executable
  2. Add SKQueue as a dependency to your Package.swift
import PackageDescription

let package = Package(
  name: "SampleProject",
  dependencies: [
    .Package(url: "https://github.com/daniel-pedersen/SKQueue.git", majorVersion: 1)
  ]
)
  1. Fetch dependencies. swift package fetch
  2. (Optional) Generate and open an Xcode project. swift package generate-xcodeproj && open *.xcodeproj

Usage

Example

class SomeClass: SKQueueDelegate {
  func receivedNotification(_ notification: SKQueueNotification, path: String, queue: SKQueue) {
    print("\(notification.toStrings().map { $0.rawValue }) @ \(path)")
  }
}

let delegate = SomeClass()
let queue = SKQueue(delegate: delegate)!

queue.addPath("/some/file/or/directory")
queue.addPath("/some/other/file/or/directory")

Output samples

Action Output
Add or remove file in /directory ["Write"] @ /directory
Add or remove directory in /directory ["Write", "SizeIncrease"] @ /directory
Write to file in /directory/file ["Rename", "SizeIncrease"] @ /directory/file

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

v1.1

  • Added method fileDescriptorForPath to SKQueue
  • Added delegate parameter to SKQueue initializer

v1.0

  • New API (see example above)
  • Removed extension of the SKQueueDelegate protocol (see below)

v0.9

  • Legacy API (see source)

Migrating to v1.0

The naming and ordering of parameters have changed, Xcode points this out at the appropriate locations.

If you have been using the overloaded receivedNotification that takes strings, you need to manually extend SKQueueDelegate as follows

extension SKQueueDelegate {
  func receivedNotification(_ queue: SKQueue, _ notificationName: SKQueueNotificationString, forPath path: String)
  func receivedNotification(_ queue: SKQueue, _ notification: SKQueueNotification, forPath path: String) {
    notification.toStrings().forEach { self.receivedNotification(queue, $0, forPath: path) }
  }
}

skqueue's People

Contributors

chrischares avatar daniel-pedersen avatar jrapoport avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.